#archived-code-general
1 messages ยท Page 263 of 1
Note that I'm not sure if it will work when run in game, I just tested it in editor mode XD
that actually works but there a problem that comes to this
the mouth left and right have different propertys
the plan is to basically let the game know if he is facing left to change the angles of all the armitures to mirror animation
Actually now that I think about it. This could save me on resources
So umm i was wrong there are many issues when it comes to this
Hi, I have a model which has a bone structure with objects added to the end, which are rotating in an endless loop. This is pared with the rest of the mesh which is not animated. I want to try and convert this object to a single entity. Is this possible or would it come out as 2 entities. One which holds the animation and one which holds the other static mesh?
This isnt a code question. To somewhat respond, this all cant just be 1 object if parts of it are moving. It wouldnt really make sense
i'm trying to distribute a points on a scale of 1 to 10 evenly using this code, but it's just spitting out 0s:
private float[] scale;
// Start is called before the first frame update
void Start()
{
scale = new float[5];
for (int i = 0; i < 5; i++)
{
scale[i] = i / (5 + 1);
Debug.Log(scale[i]);
}
}
you are doing integer math
i dont understand
do you know the difference between integers and floating point numbers?
not code general
int 1/int 2 =0
just slap an f on one of those magic numbers
ok
why?
why is 1/2 = 0 in int
because ints cannot have decimal places
๐คฆโโ๏ธ im dum
so then the answer to this question #archived-code-general message
was very likely "no, i do not know the difference between integers and floating point numbers"
no i just had a brain malfunction
so how can i fix for this code:
im trying to distribute points evenly on a circle
cast i to float
what is currently wrong with it
its still giving 0
and you've actually saved/compiled the code after making that 1 a float?
well casting i to float wouldn't be necessary if the denominator is already a float because int divided by float returns a float
no but it only worked after casting i to float, idk
prove it by removing the cast
does that function correctly map the values evenly from 0 to 1?
k wait
range of i is [0,count-1] where dominator is count+1
looks like you need one more position
ok, i just didnt save it before playing, it works perfectly
lol
Classic
the mapping code supposed to give 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9. but its giving:
anyway, this is what i had done for something similar. I was shooting raycasts in a cone/circle rather than putting points on a circle, but the concept is really the same
var maxAngle = _fovAngle / 2f;
var offset = _rayCount > 1 ? _fovAngle / (_rayCount - 1) : maxAngle;
for(var i = 0; i < _rayCount; i++)
{
var angle = -maxAngle + (offset * i);
var dir = Quaternion.AngleAxis(angle,Vector3.up) * transform.forward;
Debug.DrawRay(transform.position, dir * _rayLength, Color.green);
}
y isnt mine woring
Btw the Mathf.Clamp line does absolutely nothing
Guys, are fancy filters supported by AssetDatabase.FindAssets? I'm trying the code below but always gets 0 results even when the file do exists:
string[] guids = AssetDatabase.FindAssets("p: dir:\"UI/Controls\" MyFancyUIDocument.uxml");
It does work in Unity's search utility ๐
cuz u arent rounding anything
ur using the values you get without like "smoothing" them
no i figured out, since i is not actually from 1 to 10 but from 0 to 9, u just dont add 1 to the denom
also seeing the rest of your messages, you might want to take a basic C# course
hello
i kinda need help
cool, why dont you start by asking your question
dont cross post
Looks like we can't.. the thing is using t:UXML also doesn't work
so i follow a tutoral and he put rigid body on sb but i cant see the rb place on mine i have exactly the same code
want to get yeeted by a mod ?
stop cross posting
stop crossposting. you've been answered in #๐ปโcode-beginner
wth is cross posting
posting your question across multiple channels
you very clearly are a beginner and ask beginner question, there is a seperate channel for that, please ask in #๐ปโcode-beginner if you have such beginner questions the next time
ya il post there from now
Also please look at a C# Tutorial so you understand the coding language
i just saw general and popped in here
no i understand c#, i actually made a monogame game once, its just i forgot integer math
(i dont know how making a monogame game proves my c# intellect but... just trust me)
you dont just forget interger math
i dont like int
unless you dont code much or like had a big pause
anyways before asking such basic stuff again, look at these to refresh your knowledge, should help you get back in:
https://www.youtube.com/watch?v=gfkTfcpWqAY
https://www.youtube.com/watch?v=XtQMytORBmM
C# tutorial for beginners: Get up & running with C# and code in just 1 hour! No prior knowledge needed.
- Get my full C# course: http://bit.ly/2KJLPuS
- Subscribe for more C# tutorials like this: https://bit.ly/38ijYjn
โญ๏ธWant to learn more from me? Check out these links:
Courses: https://codewithmosh.com
Twitter: https://twitter.com/moshhame...
๐ด Get bonus content by supporting Game Makerโs Toolkit - https://gamemakerstoolkit.com/support/ ๐ด
Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then gi...
btw if i needed someone to playtest my game, is there a channel here for that or am i gonna have to make friends
Friends
or put it on itch, with the warning that its a playtest / alpha
but what if i finished only the movemnt and wanted someone to tell me if it feels well
its like 1 minute of playtesting or smth
like, the art is just borrowed from random files i have from modding games (this one is from celeste)
what happens if a server passes in a wrong argument in a client RPC which will lead to a error on a client (listOutOfIndex) will the client crash or will it be ignored if so will the list return null?
it will throw an exception on the client just like doing that in any other context would
whether there are ramifications depends on the actual context of the exception just like literally any exception
also #archived-networking for networking related questions
k, thanks.
I'll use labels then.. ๐
that depends strongly on your network library
and yes #archived-networking might be better
You are mixing backslashes \ and forward slashes /. Is that intentional?
The backslashes seem out of place in the code, especially the first one
they are escaping the "
so, i am using asset bundles for mods and it works perfectly, however, if i spawn a prefab, audio clips are not found, even tho they are in the asset bundle too
How is audio referenced
it is just inside of an audiosource within the prefab, but the clips are also iuncluded in the asset bundle, do i have to load them manually?
Should not have to, as long as the audio clips are referenced they should auto be included in the bundle and get loaded with it
hmm ok...
If you don't manually include the audio clips, I would check and see if they get auto included because the prefabs reference them
i just tested it, looks like it does, yes
Strange, and in the asset bundle browser you can see the audio
browser?
u mean in unity in the folder?
https://docs.unity3d.com/Manual/AssetBundles-Browser.html
It's a tool for just lets you look in built bundles
Oh what was it very curious?
the object the audio source is on has to be active, in the prefab it was not active because i set them active in a function
very strange
why is it like this tho
the modles which are not active work
Hmm never run into that before, but it seems very counterproductive
Will test when I get to work later
What unity version?
Work around I guess is keep then active in prefab and disable on Awake
Hmm will look at that later, I am using 2022.3 for a project at work too. Though using addressables not bare asset bundles
not a code question #๐คโai-navigation
Ups
What would be a solid solution for detecting when something can jump to follow something?
I was thinking something like shoot a raycast in the direction of the prey, if it hits something, shoot another raycast from that X but the Y of the prey, and if that hits then presume you can jump to the ting
ontriggerenter calls both ways right?
like it calls on a trigger when it enters a collider or no
no
im wrong
how can i create a mask inside which i can draw a texture using a list of points
OnTriggerEnter is called on both objects involved in the trigger overlap. This can be two trigger colliders or one trigger collider and another non-trigger collider
so if a trigger enters a non-trigger is ontrigger enter called on the trigger?
i have this line renderer that displays the edges (the blue thing) i want to fill it with a texture
k il wait
OnTriggerEnter will be called on both, yes. provided there is a rigidbody on one of the objects
https://unity.huh.how/physics-messages/trigger-matrix-3d
oooh thats
interesting
you should use a polygoncollider
unsure how to fill it with a texture, but you could use an occlusion mask(?) to just render that texture everywhere but have it be hidden outside the area
ya thats what i was thinking
although i've only done that the other way around, having it be vis everywhere except the target area (for flashlights)
so basically (if u read my prev msgs) i make those points move in a circle. its likea slime character but using rigidbody physics so i will use these points to render the skin of the player but make them have wall collision and stuff, so itl feel more softbodylike
but i didnt think abt how i can make the texture inside respond to movement
i havent got this figured out yet
if the player moves the points rotate clockwise or anti clockwise (right and left respectively), i want to make a fill that's mostly procedurally generated
so a texture wont work probably
mabey a gradient fill between each points
will i be able to generate a mesh to fill the inside of the polygon and use an uv
so i could to warping and stuff
You can generate a mesh, yes
You can even generate a skinned mesh (mesh with bones), it could fit the usecase for softbodies
Skinned mesh would be good since you wouldn't have to regenerate the mesh every frame, just move the bones to warp it
idk how
It's a bit more advanced though since you have to generate bone weights/bind poses
where can i learn
You can get started with mesh generation here:
https://catlikecoding.com/unity/tutorials/procedural-meshes/
It doesn't cover skinned meshes/bones though. That's more advanced stuff.
If you don't like reading then I don't have any video tutorials to suggest but they probably exist
just an idea wouldnt it be just easier to have a circle with a slimey shader ?
ooh
Sure if that's what they want
whats a slimey shader
I didn't read the whole convo tbh
a shader that makes the object look like slime
does it give like textureing and stuff
i also want it to jiggle
yep can all be done in shaders
sounds way less complex then your way of archiving it imo
but not affect other objects due to jiggling
check the docs pinned in #archived-shaders
how are you always sniping my answers
what if i first hit an object, then hit another? Will **OncollisionEnter **get called twice and **OnCollisionExit **not at all (if i still touch them) ?
Or is the method OncollisionEnter going to be called once, but will contain contacts for both objects that i collided with?
OnCollisionEnter would be called twice there, yes. And OnCollisionExit will only be called if any of the pairs of objects colliding stop touching
Every Physics update, Unity generates a bunch of collisions. Then, for every Collision, it checks both things in that collision for OnCollisionEnter/Stay/Exit, and invokes the relevant one if it finds it.
If one gameobject is involved in multiple collisions, then it will potentially get multiple calls on that frame.
Beware that collision calls are not invoked in any particular order
If mario collides with a super mushroom and a goomba in the same frame, and you detect by OnCollisionEnter, then you better make sure the same thing happens whether the mushroom or goomba collision gets called first.
I was like "damn, its only 930? it feels like its been much longer"
then I realized its because I was not used to being this productive ๐
how can you create a custom character collider?
I'd like to try and make my own custom controller, without using unity's physics or anything
and I'd like to make it cylinder shaped, and not a capsule, but how would you detect collision?
without using Unity physics at all? Then you're basically talking about building your own physics engine from scratch. Not a small feat
well, I'm not totally insane
You're better off using a kinematic Rigidbody and a Cylinder-shaped mesh collider
raycast based, rather than collider based
You can use this https://docs.unity3d.com/ScriptReference/Rigidbody.SweepTest.html
I've actually tried cylinder shaped mesh colliders before, and it's not super smooth which is why I'd like to try this
Custom collider shapes aren't possible
it's not that important to me I just always wanted to try this out
aside from MeshColliders
oh yeah I know, I just thought like
surely there's a method of raycasting that can allow custom shapes? idk
For casting shapes you either do Rigidbody SweepTest with a MeshCollider (custom shape)
Or use the existing methods here:
https://docs.unity3d.com/ScriptReference/Physics.html
There is no custom shape casting other than SweepTest
hmm alright
I'm mainly asking because I saw a tweet by a guy making a skating game
and his entire thing is ps1 styled so his character doesn't use rigidbody physics
the map is still made of colliders obviously but it doesn't like, use physics like that it's all raycast based
He is using some combination of these things #archived-code-general message
does anyone have template for a runner game like subaws surfer ?
ah neat!
i mean this would require using a rigidbody right?
sweeptest would
but I don't see the issue with having a Rigidbody
just make it kinematic
oh yeah but there's checkcapsule too fair
oh there isn't this is more for like
You can also just use this https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131
idk fun? try make a character controller without the colliders and stuff
oo
I am gonna download this and rip it apart and find how it works
that sounds extremly unperfomant
Raycasts are extremely cheap
Maybe I'm missing something else?
Arent they quite heavy in big amounts ? Especially in the amount you would need with a character controller
No. A single raycast is almost free honestly. Scaling up is cheap
You can use a LOT of them no problem
It's a common misconception that they are expensive though
I am currently using Kinematics Rigidbody for all of my GameObjects and currently trying to set up my own physics sytem. I have recently read an article about Integration Basics which covers Semi-Implicit Euler, Explicit Euler, and RK4. Here's the implementation code: https://paste.ofcode.org/Mc7kMmw9gNLunsDNZDiMxS. I wonder which system would suit best a 2D top-down game. The article also mentions symplectic integrators but I still wonder which one is great. Can someone give me some recommendations?
Hello! I'm working on this turret, and for the first few seconds the bullets move as expected. But then after a couple of seconds the bullets fly to the left side of the turret. How can I fix this?
This is what I've got for both the turret and the bullet.
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Turret: https://gdl.space/abuneserum.cs
Bullet: https://gdl.space/abesosubob.cs
I would suggest, looking at your code, that the problem lies with Lean Pool
Although maybe you dont want firePointL.rotation or firePointR.rotation but firePointLforward and firePointR.forward
In LeanPool.Spawn?
I have no idea what LeanPool is but LeanPool.Despawn(this) looks odd to me
Seems like an Object Pooling script
for all I know it could be a subscription to the local swimming pool, lack of information
https://assetstore.unity.com/packages/tools/utilities/lean-pool-35666
seems like it's from the asset store
Well if it is object pooling why Spawn a gameobject and Despawn a script ?
Did the issue get fixed? I wanna ask if you did actually spin the turret while firing the bullets
I got it fixed in another server
It turns out that for the bullets I needed to use OnEnable instead of Start because of LeanPool
But thanks for helping out!
So I wasn't far off, not bad for a guess
I just made an override of a super complicated script with a bunch of variables that I'd have to reassign, but unity won't let me copy and paste the values into the override, is there any way to fix this?
custom editor
can you elaborate?
sure, data is type specific i.e. is linked to the type of the class. in order to overcome this you need to write a custom editor to expose the underlying class to the editor rather than the inheriting class
Alright, I'll try
if i have Update in a class as well as in it's child class (both private) do they both run?
No. The Update method from the actual runtime type will be executed.
so the lowest public one I presume?
If you want to run both, make the parent method virtual, override it in the child, and call base.Update(); in the child
If you have an instance of B, you'll get B's Update method
This is what the Selectable class does
cool
Hello everybody! I am having issues building (for windows). The build is taking longer and longer each time, but more importantly: the first time the game loads, it seems multiple effects are disabled (post processing, volumetric fog, some materials). after reloading the scene in the game, it looks OK. I tried loading other scenes before and then my main scene, but it still looks wrong the first time. Does anyone has an idea about what could it be? (everything works fine in the editor)
It can be private
cool
public void ShuffleClats(){
foreach (var item in SpawnedClats)
{
if(item.GetComponent<Loot>()){
item.GetComponent<Loot>().enabled = false;
}
var BasePos = item.transform.position;
var RandOther = SpawnedClats[Random.Range(0, SpawnedClats.Count)];
transform.position = RandOther.transform.position;
RandOther.transform.position = BasePos;
}
}
I had hoped this code would shuffle around a bunch of objects, but that does not seem to be the case, I get a result like this (note the stacking)
any idea why?
(ignore the loot disabler that is not important to the rest of the function)
noooo wait something isn't working right
its not disabling the loot script and I can't collide with them anymore
(Or protected if you need to override it/access it from child class)
Shouldn't transform.position = RandOther.transform.position; be item.transform.position = RandOther.transform.position; ?
im so dumb
Also better way to write that Loot thing:
if(item.TryGetComponent(out Loot loot)){
loot.enabled = false;
}```
instead of GetComponent twice
Small tip, you can replace the double GetComponent with ```cs
if(item.TryGetComponent(out Loot loot))
goddamnit praetor

Or even have the list as List<Loot> if possible
If it doesn't always have a Loot component then no
does not always have a loot component
also I use SpawnedClats in a lot of other places so changing the type would mess up things
uh
ok so
you know school gyms
they have those little like
smol cones?
im calling those clats bcause y not
these things
Ah those
(except these ones animate and swarm you but potato potahto)
I wanted to shuffle them so the one that detects you/is shootable is not the same for each iteration
oh, those doohickeys
these frikin guys are as buggy to all hell
sometimes they do damage you, sometimes they dont. Sometimes they grab you correctly, sometimes they dont. Sometimes the hand moves right, other times it gets stuck
its infuriating
i'll fix em later tho
I have a question. In Unity, how do I swap a Skinned Mesh Renderer with another mesh thats in an already loaded asset bundle? I was told to use this __instance.gameObject.GetComponent<SkinnedMeshRenderer>().sharedMesh However I don't know exactly how to specify the mesh from the asset bundle when using this.
I have confirmed that the asset bundle I am using already is loading properly.
What collider, how are you moving it and how are you using it (OnCollisionEnter/TriggerEnter?)
Im fine if it passes thru things just preferably it would detect when it ran into something with OnTriggerStay or OnCollisionStay (2D)
moving it with changing transform
ill finnik with a couple things first hmm
can I depend on an asset inside Resources/ directory, so that when it updates, the dependent scripts also update?
I don't know what that means.
"The dependent scripts also update"
Are you trying to make a "manager" object that runs methods on a bunch of other objects?
I am in a process of writing a package, and it depends on some shader partials (.hlsl files) that are later #included in a shader, but this shader is generated by a custom asset. I want it to behave in such a way, that when the included .hlsl file changes, it takes effect in unity, so possibly notify the shader-generating asset that the include changed, so the final shader has to recompile
ah, okay, you're talking about shader compilation
do you know what a reference is?
I am trying to write a custom asset (or something) that generates a shader source. This is an editor utility btw
you mean asset GUID?
I thought Tooster was talking about something happening at runtime with component instances. That is not the case.
no, just in general, because it sounds like you think when you reference something it makes an actual copy
I'm not familiar with how Unity deals with changes in #include'd shader files
yeah, I know what references are. I think I struggle with the editor asset pipeline and how unity determines how to "update" (recompile/reimport/do something) to assets that reference other assets.
I can tell you exactly how Unity handles things like that, very badly in the editor but well at build time
I've taken a look at how ShaderGraph tries to manage dependencies (for example for "default includes" in generated shaders), but shadergraph is such a big pile of code that it's pretty hard to understand how it works exactly, and i only want something simple for now https://github.com/Unity-Technologies/Graphics/blob/d13e988448aa2ec3b05cb525f7f9b9a587cc5a80/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs#L67
if in doubt write your own AssetPostProessor to handle dependencies
idk If i'm not in the XY problem territory, because for now I have a "common shader include file.hlsl" inside a "Package/Editor/Resources", and I just didn't see any change when I updated the .hlsl file that the final shader recompiled or updated (and the method for generating final shader returns a fixed string right now that simply imports this include)
Yeah, probably will have to do that, just that the whole "custom assets" thing seem very convoluted and hard to understand.
AssetPostProcessor is actually pretty simple
hmmmm
I wonder what is causing this
wait does that store all the debug.logs or warns?
yes, of course, it's a log
I need help for some wheel colider that doesnt wana move
Cool
Hey all, just some quick math things, if I'm trying to calculate the length of an Image via the length of a song, and it's BPM, how would I do that? I know it has something to do with speed = distance / time but I suck with game engine math and honestly couldn't think of any better math to use here
Here's the same timeline from a few days ago, I just need this to explain the other metric I have
wdym by "the length of an image"?
I mean like, how long an Image is supposed to be to accomodate the length of a song
Like, I have a line running through the entirety of the timeline, which just shows the current position of the song, like how Unity Animation Panel works?
I'm not sure how to incorporate in into a formula to use though
How are they related?
Wouldn't the image size itself always be the same?
It's more a question of positioning objects (notes) along the line
oh, sorry
the image in this case is the lines. They need to be longer to accomodate the entire song
yeah isn't that always going to be the same length?
unless I'm going about this the wrong way
Yeah, essentially
there are many ways to do this
It's scrollable and has objects that are dotted along the timeline, depends where the user wants to place events dwon.
I don't think BPM has anything to do with this particular calculation. It's basically just totalSongDurationInSeconds * pixelsPerSongSecond
I'm having a really hard time working with Elevenlabs. It's 50/50 when the files are playable.
I have a good file and a bad file I have saved.
From the bad file I get this error: Error: Cannot create FMOD::Sound instance for clip "" (FMOD error: Error loading file. )
The good file plays without any issues.
Both files play in external players, ran both files through file analysis and all the metadata looks correct.
I'm not sure what to do at this point.
UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file://the path".Replace(" ", "%20"), AudioType.MPEG);
req.SendWebRequest();
var clip = DownloadHandlerAudioClip.GetContent(req);
if (clip.length == 0)
{
Debug.LogError("bad file failed");
}
so I use async tasks to use multithreading, but I forgot how I used to effectively deep profile specific parts in the async task functions. Whats the proper way to profile these on the CPU?
I have also been having difficulty with finding info on this for specifically async tasks, as I often get a bunch of less than useful stuff not actually relating to tasks themselves
sounds like they were recorded with different codecs, one of which FMOD cannot handle
Looks like there is something wrong with the bad file, tried another site and it can't detect the bad file encoding but it can the good file.
This then would sound like what Elevenlabs is sending back is bad
yes, or they are using some kind of custom codec
can you not chose the codec to use for the recording?
anyway probably not a code problem, maybe better in #๐โaudio
I wasn't not sure the default, maybe something with they. I do have these options:
PCM_24000 looks like the default
Does anyone know if I can Center my line reneder on a navmesh surface?
the rainbow line is what gets generated , the black line would be what im trying to achieve , the clean corners
MP3-44100-x (probably 128) would be more common
Well the line renderer is based on the navmesh path I assume, so really you can do whatever you want in regards to the line renderer. In terms of the path, it calculates an optimal path, what you've drawn is not optimal so it will not get this result. You'll have to implement your own solution
ok , on to google to see what I can figure out
thankyou
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
yeah srry iknow
https://gdl.space/apetohipob.cpp does anybody have any idea why the camera doesnt just clamp between the 2 values?
rotation is a Quaternion, you are treating it as an Euler
Updated to MP3-44100-128, same issues.
I'm going to reach out to elevenlabs.
so It's not the line renderer I create my soulition for , It would be the navmesh path , keeping the corners (the points where the line turns) twards the center or more lined up right?
i mean thats the only thing i can find on the internet on how to do it like every forum has this line code to use for limiting the rotation so i thought this was the right way. what can i use to make this work? bc im kinda lost tbh
this
Mathf.Clamp(cam.transform.rotation.x
is never gonna work because .x is a Quat value
Really shouldn't be trying to clamp values read from a transform's Euler rotation either. You should track and clamp your own values that are then applied to the transform
Or, better yet, use Cinemachine and don't write your own camera controller
Up to you, if you want the agent to move along the exact same "centered" path then yea itll have to be solved for the path.
hi, im making a room spawn system that spawns a series of rooms in a random order, the way i have it done is for each room theres an empty game object (or more) called room connectors. these spawn other rooms at their position and rotation. the problem is that some rooms have room connectors on all sides, and sometimes (most of the times) some rooms end up clipping through eachother. heres a pic and the code. if theres a way to do it without a grid system then that would be amazing, this is what ive been trying but i cant get it to work. if anyone has any idea why please tell.
https://pastebin.com/GiGX91Cs
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
You could do a Physics.CheckBox/OverlapBox or some other physics query to detect if a space is taken
Or even Rect.Overlaps if you convert the XZ coordinates into 2D rects (and the rooms are never rotated)
Or Bounds.Intersects if you need verticality
Hello! I want to make a game with PCG platforms. The 'routes' will be created out of chunks of platforms/blocks(4 types to be exact for now) and they all square. By chunks I mean there will be different widths and lengths to them and they will have a route(doesn't have to be straight for or fully filled with max width of blocks and length.
Anyways, does anyone have an Idea how and where can I find algorithms for these kind of PCG?
thats what im doing
i linked the code
Oh I missed that
Checking the rotation with == seems a bit sketchy. Not sure if that is reliable
This etc. roomConnPos.rotation==Quaternion.Euler(0,-90,0)
Looks like you have the "edge case" log which would inform you if anything went wrong. Does that ever log?
nop
how should i check it then
Not sure, I would personally probably store it in a simple variable like a float (y angle) or an enum
The way you are doing it might be fine though.
One thing that comes to mind is that you might have to call Physics.SyncTransforms after spawning a room
oh, ill try that
I also suggest that you confirm that your OverlapBox is correct
With Gizmos.DrawCube or something like that
yeah thats what i was gonna ask
how to do that
cuz ive been spawning an empty game obj with a box collider and applying the scale snd position manually
OnDrawGizmos, loop your connections and use the same values for Gizmos.DrawCube
Or Gizmos.DrawWireCube
okay
yes
I don't see you taking rotation into account in your overlapbox
That might actually be the reason
Yeah your OverlapBox is using a zero rotation by default
Try giving it roomConnPos.rotation
The center needs to be rotated too.
how do i do that
You currently have this as center:cs new Vector3(roomConnPos.position.x, roomConnPos.position.y, roomConnPos.position.z+roomDimensionsHalf[i].z*2)
You should do something like:cs roomConnPos.position + roomConnRot * new Vector3(0, 0, roomDimensionsHalf[i].z * 2f)
If I understand your code correctly
lemme try
roomConnRot * rotates the vector after it
@knotty sun ended up switching to google's speech to text away from elevenlabs, issue resolved.
You can rotate a vector by multiplying it with a quaternion
@half sphinx See the edit, I added roomConnPos.position
yeah i added that too in the code
You have those if-statements just for different rotations, right?
I think you can just get rid of them
And use one OverlapBox that takes rotation into account
nothing changed tho, for some context, the scene has a room that has 3 connections, only one room spawns and the console spams cube like 5 times
yeah i did that
Try to set up the Gizmos next
@half sphinx When doing procedural stuff, visualization is important so you know what is actually happening
https://pastebin.com/w4XC5VDe updated code btw
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
working on it
You need to make sure that the overlap won't hit the 'parent' room too
The one you are connecting to/from
Alright
4 should be a perfect fit tho
I would use 4 and then loop the colliders that OverlapBox returns
Only return true if they aren't the parent room's collider
Alternatively you can disable the parent collider first, then do the check, then re-enable it
yeah
but for now
ill get to the point where rooms spawn and then worry abt that
also, how exactly should i draw the box, ondrawgizmos cant take any inputs
wait no
nvm
Oh yeah since you have rotation, you need to use Gizmos.matrix
i was just abt to ask that
Gizmos.matrix = Matrix4x4.TRS(pos, rot, Vector3.one);
Gizmos.DrawCube(Vector3.zero, roomScale)```
Gizmos.matrix = Matrix4x4.TRS(roomConnPos.position + roomConnPos.rotation * new Vector3(0, 0, roomDimensionsHalf[i].z * 2f),roomConnPos.rotation, roomDimensionsHalf[i]*3.9f);``` this right?
I edited a bit, maybe easier to set matrix scale to Vector3.one and then draw the cube with the actual scale
Note that DrawCube wants full size, not half size
And it needs to be in OnDrawGizmos (or OnDrawGizmosSelected)
Yeah, think of it like making the gizmos a child of something
After that, everything will be drawn relative to the matrix you gave it
So Vector3.zero as position will actually be the room position you put in the matrix
aha
Show the code you used for that
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i think the gizmo is correct
hopefully
yeah but how do i pass roomConnPos to it
Do a foreach loop for the connections
ok
And set the matrix again every iteration
Hi, I'm new to this server. I have a question to ask, should I wait until your conversation is over or can I just throw it out there?
Oh you meant in code, lol. Yeah no
{
if(started)
{
foreach(Transform roomConnPos in roomConncections)
{
Gizmos.matrix = Matrix4x4.TRS(roomConnPos.position + roomConnPos.rotation * new Vector3(0, 0, roomDimensionsHalf[i].z * 2f),roomConnPos.rotation,Vector3.one);
}
Gizmos.DrawCube(Vector3.zero, roomDimensionsHalf[1]*2);
}
}```
this should work right
Ask away
DrawCube goes inside the loop too
Other than that, it looks ok to me
Thanks! My issue is with my background animated graphic rendering above my UI text. The background graphic is an empty object containing a LineRenderer script that generates a wave (sine curve). However it obscures my UI text. I used separate Sorting Layers to try to fix it, with the UI sorting layer being above the Background sorting layer - to no avail! Should I post some screen shots?
Also do the * 3.9f multiplication in Gizmos too. Currently you only have * 2. It should be * 2 * 3.9, or whatever is double of the scale you use in the other method
What type of component is the UI text?
Just wondering if it's world space TextMeshPro
Or maybe your canvas is in world space
It is Text Mesh Pro, I'm using the asset Doozy UI Manager to create all my UI elements. It's a title of Text Mesh Pro inside a View, inside my Canvas which is set to my UI sorting layer.
The UI sorting layer is layer 2, and the Background sorting layer is layer 3, so it should be behind.
Let me check for World Space, that may be the issue.
The Canvas is set to Screen Space - Camera.
I don't see anything on the LineRenderer object showing world space or screen space.
2* is actually the correct size , its just off a bit
Alright, well now you have the tools and knowledge how to debug it further
Since you can see what's going on
I hope the gizmos are correct, I'm pretty sure they are
Actually, there is a checkbox on the LineRenderer that says Use World Space, and that's checked.
Yeah that's fine
Unchecking it didn't make any difference.
I was asking about TextMeshPro because there are two types, one for UI and one for world space UI
And AFAIK a linerenderer should always render behind normal UI (which is what you want, right?)
Might depend on the material on it, though.
Yes, I want the line renderer to render behind UI
The pink curve should be behind the UI text.
How do I check which type of TextMeshPro I'm using?
I'm happy to change the material on anything if it helps.
Show the inspector of the object that has it
This is the Title that renders behind the LineRenderer
Yeah that's the UI version which is fine. I don't know, could be something related to the asset you mentioned. Ask in #๐ฒโui-ux instead, this is a code channel anyway ๐
This is my Hierarchy, the Wave01 object at the bottom is the LineRenderer that makes the curve.
Hmm so the linerenderer is a child of the canvas?
Ok, thanks!
No, it's outside of the Canvas.
I tried putting it inside the View and it didn't make any difference.
Everything from EventSystem down is outside of the Canvas.
Okay, thanks for your time.
they should be now, i hope, still some weird behaviour happening but ill try again tomorrow
but if that still doesn't work and i give up on physics.overlap, are there any other options
Is there a way to pull a vector2 and tell what direction that character is moving? I am trying to set up an animation to change from left to right and the character moves on the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour
{
public float speed = 8.0f;
public float speedMultiplier = 1.0f;
public Vector2 initialDirection;
public LayerMask obstacle;
public Rigidbody2D rigidbody{get; private set;}
public Vector2 direction {get; private set;}
public Vector2 nextDirection {get; private set;}
public Vector3 startingPosition {get; private set;}
private void Awake()
{
this.rigidbody = GetComponent<Rigidbody2D>();
this.startingPosition = this.transform.position;
}
private void Start()
{
ResetState();
}
public void ResetState()
{
this.speedMultiplier = 1.0f;
this.direction = this.initialDirection;
this.transform.position = this.startingPosition;
this.rigidbody.isKinematic = false;
this.enabled = true;
}
private void Update()
{
if (this.nextDirection != Vector2.zero)
{
SetDirection(this.nextDirection);
}
}
private void FixedUpdate()
{
Vector2 position = this.rigidbody.position;
Vector2 translation = this.direction * this.speed * this.speedMultiplier * Time.fixedDeltaTime;
this.rigidbody.MovePosition(position + translation);
}
public void SetDirection(Vector2 direction, bool forced = false)
{
if (forced || !Occupied(direction))
{
this.direction = direction;
this.nextDirection = Vector2.zero;
}
else
{
this.nextDirection = direction;
}
}
public bool Occupied(Vector2 direction)
{
RaycastHit2D hit = Physics2D.BoxCast(this.transform.position, Vector2.one * 0.75f, 0.0f, direction, 1.5f, this.obstacle);
return hit.collider != null;
}
}
I want to make a new piece of code and just get the vector in order to set the animation each time the direction swaps from left to right but trying to print the Vector2 value in a debug log didn't enlighten me as to how best to do that.
le epic
What vector safe you talking about? Where do you debug it?
Type normally. This title-case stuff is obnoxious and unreadable.
ok
So I have a game where you can shrink and grow. The scale is set via a script. You can also spawn props like a crate and chair. But when you spawn props that are a different size the contact offset in unity by default does not change. I tried changing the collider offset still no change. This causes OnCollisionEnter to fire way to early ruining the effect of a sound when it hits the ground. When the prop is small the radius is too big, when the prop is big the radius is too small. I am using Unity version 2021.3.26, my colliders are mesh colliders that are convex and I am changing the values by an array of colliders (private Collider[] colliders).
What do you mean by a "contact offset"?
If you go to physics in the project settings there is a setting named default contact offset. You can set this via a collider reference.
I'm not sure how that setting is relevant to anything..?
*to your issue
It's basically when the collider point is less than the distance. It calls stuff like OnCollisionEnter. And I use that to make a sound when the object collides with the ground. But when the object is small it does not change causing the collision to detect to early. I tried setting the colliders contact offset via script and it did nothing.
Why would your colliders be smaller than .01 units..?
I'm sure that's gonna break more things than just the collision events.
And if not, it should really make any difference at all. .01 is a very small distance.
void Start()
{
dropdown.ClearOptions();
List<TMP_Dropdown.OptionData> dropdownOptions = new List<TMP_Dropdown.OptionData>();
dropdownOptions.Add(new TMP_Dropdown.OptionData(""));
foreach (ItemEffect itemEffect in itemEffects)
{
dropdownOptions.Add(new TMP_Dropdown.OptionData(itemEffect.name));
}
dropdown.options = dropdownOptions;
dropdown.onValueChanged.AddListener(delegate { ApplyitemEffect(dropdown); });
dropdown.value = 0;
dropdown.RefreshShownValue();
}
Hi, I cant see my dropdown text after update to unity 2022.3.16f1. The text can only show when the dropdown option is selected. How to solve it?
before selected
after select
can i ask about visual studio stuff here?
hello, im looking for some help with my game to get my enemy to move and attack the player if someone can help me that would be great
What's the issue and what do you have so far?
I had attached a debug log just to get the direction for that specific character and print it but I think I did so incorrectly. I'm not really the programmer, I'm just supposed to implementing animations here. The vector I though I could use was the one named "direction". Sorry for slow reply, got busy with other stuff.
I don't see you a debug log anywhere in the code you shared, so I can't say if it was correct or not.
I have tested in new scene and the test show. What could be the problem in my original scene?
the character doesnt move or it will walk into a object and stop moving
Share the relevant code.
Yeah we had to revert the code due to a github merge corrupting some stuff, but basically it's a generic movement script attached to 4 different characters, and it most likely wasn't correct. What would be the best way to go about writing a debug log for one of the characters it's attached to?
Make a check if it's the character you expect and debug if it is.
Got it, thank you.
How would I get this kind of behaviour without parenting?
Where it follows the point, at an offset. It also rotates with that point, keeping that offset.
[RequireComponent(typeof(Rigidbody))]
public class GrabInteractable : MonoBehaviour, IInteractable {
private Pose grabbedPose;
private Rigidbody rb;
private void Awake() {
rb = GetComponent<Rigidbody>();
}
public void OnPicked(Hand hand) {
grabbedPose = new(hand.transform.position - transform.position, hand.transform.rotation * Quaternion.Inverse(transform.rotation))
rb.isKinematic = true;
}
public void OnHeld(Hand hand) {
transform.position = hand.transform.position - grabbedPose.position;
}
public void OnDropped(Hand hand) {
rb.isKinematic = false;
}
I already have the position part working
but the rotation has me stumped
Hey guys ๐ im trying to add ground detection through raycast but my current logic uses on collision. i am for some reason having trouble separating grounded logic from on collision.
private void OnCollisionStay(Collision other)
{
// Make sure we are only checking for walkable layers
int layer = other.gameObject.layer;
if ((int)whatIsGround != ((int)whatIsGround | (1 << layer)))
{
// If the collision is not with a walkable layer, exit the method
return;
}
for (int i = 0; i < other.contactCount; i++)
{
Vector3 normal = other.contacts[i].normal;
// Check if the collision is with a floor
if (IsFloor(normal))
{
// If wall running was active, disable it
if (wallRunning)
{
wallRunning = false;
}
grounded = true;
normalVector = normal;
cancellingGrounded = false;
CancelInvoke("StopGrounded");
}
// Check if the collision is with a wall and on the Ground layer
if (IsWall(normal) && layer == LayerMask.NameToLayer("Ground"))
{
// Start wall running
StartWallRun(normal);
onWall = true;
cancellingWall = false;
CancelInvoke("StopWall");
}
// Check if the collision is with a surfable surface
if (IsSurf(normal))
{
surfing = true;
cancellingSurf = false;
CancelInvoke("StopSurf");
}
// Check if the collision is with a ceiling
IsRoof(normal);
}
float num = 3f;
// Schedule methods to stop grounded, wall run, and surf after a delay
if (!cancellingGrounded)
{
cancellingGrounded = true;
Invoke("StopGrounded", Time.deltaTime * num);
}
if (!cancellingWall)
{
cancellingWall = true;
Invoke("StopWall", Time.deltaTime * num);
}
if (!cancellingSurf)
{
cancellingSurf = true;
Invoke("StopSurf", Time.deltaTime * num);
}
}
Looks like you have a lot of different logic happening there (grounded, wall stuff, surfing stuff), I would try to move each of those into their own functions, if youd rather use a raycast instead of a collision check, often youd do those ray checks frequently, such as in Update or FixedUpdate, and in the Physics class, some raycast calls return a bool if it hit anything, if performance is a concern, you can also use non-alloc versions which return a number of hits instead of if anything was hit - see the "Static Methods" section: https://docs.unity3d.com/ScriptReference/Physics.html
For example, a typical setup might look like this:
bool isGrounded;
void Update()
{
GroundCheck();
}
void GroundCheck()
{
isGrounded = Physics.Raycast(...);
if (isGrounded) { DoGroundStuff(); }
}
You could even use another bool to track when "isGrounded" and the other bool differ, set them to the same value, then fire an event if you want to do logic on the frame that the player becomes grounded, not sure if that helps - one other note about .Raycast, is it is a single line in a direction, so cases like literally standing on edges or slopes may cause strange results depending on the origin of the cast, for those cases there is also things like .SphereCast or .BoxCast, depending on the accuracy you need, sadly visualizing the cast is a bit tricky, as youd either need to use OnDrawGizmos or Vertxyz's debugger package for anything that is not a simple ray, for that you can use Debug.DrawRay or Debug.DrawLine, which may be useful for Physics.Linecast - also, something that may help, if you prefer, you can assign layers through the inspector with a LayerMask type
What terrible advice. Yeah turn the script into a maze of one use methods.
I can only comment on the formatting, and the only thing I would change is the new line brackets and comment spacing.
Here, -20 lines - https://gdl.space/bujoperohu.cpp
Doesn't look all that crazy when you can see the whole method without scrolling. New line brackets bloat up code and make it less readable.
Im not sure I understand your concern? It sounded like OP wanted to change from using OnCollisionStay to using raycasts, and it looks like his current logic has several different things beyond just a ground check happening, which can be confusing, my suggestion is to put those into functions so its easier to manage, im not sure how that is a bad thing? I may be misunderstanding what your concern is, but it seems like you are just concerned about the bracket formatting in the example provided? Im not sure I get whats "terrible" about this, could you elaborate?
I don't agree with the idea of creating methods that are only used in one place. If you're gonna do that, you're essentially naming the code. Thats what comments are for.
void Update() { // Terrible
Shit();
Piss();
}```
Instead, because I do agree the script looks messy, you can apply some basic formatting to make the script a lot shorter than it was. Then it looks much more digestable without those one-use methods everywhere.
I don't agree with the idea of creating methods that are only used in one place
This is very commonly done for readability
readability and maintainability
yeah and I disagree
No idea how that would make your code more maintainable
๐คทโโ๏ธ you can disagree but its whats commonly done in professional environments
Professional code sucks ass. Have you ever looked at Unity's scripts?
Photon's scripts? Any large professional library's scripts?
They're horrible beyond comprehension.
i dont get your point, you'd rather all the code in one giant block? Thats your preference, do what you want in your own projects. you'll not get far in professional environments
this is just a matter of you not wanting to write it in a nice way
troll?
This is what you're advocating for
probably just a rebellious junior
C# programmer of 3 years
yes, so a junior
Not a newbie though. I've finished several projects and come to that conclusion.
this is all that needs to be said about it
reminds me of my friend who codes like shit to make his own code unintelligible so he's hard to replace (only he understands his bad code)
goodluck in the real world with your mentality
And this is my response. The words you say disconnect when you try to put it in code.
In no world is the one on the right more readble, "nicer", or more maintainable
You're just naming the code and making it longer.
and why is making it longer an issue
Typically, code would follow "S.O.L.I.D", I dont personally believe that comments should be used to organize or describe code, unless it actually adds value (such as explaining a math formula being used) - if I have a character controller, I would rather have a function for each part of my code, a function for input polling, a function for ground checks, a function for movement, jumping, abilities, etc, (or possibly states) rather than everything in Update organized by comments (which is the S of solid, single responsibility), I guess in a way thats "naming code" but you can also have your entire project on a single line of code in 1 script, itll just be impossible to debug or add features to, but it may come down to preference in code style
Less readable. Longer code takes up more space and it worse to work with.
You should always strive to make your code as short as possible so long as it doesn't impede readability
"takes more space" yea i dont wanna entertain this anymore.
says random dude with 3 years exp vs those with many years in industry
that is absolute dogshit advice
you're wacked out
not disk space, brain space
thats the stupidest point i've heard in a while
Works on my machine
we're just being trolled at this point
fr
someone makes these statements have to be trolling or have 0 clue what they're talking about, which goes well with former
Yeah, 1 thing. I guess that just comes down what you consider 1 thing to be. I think handling jump, move, and turning in a character controller is all a good thing to bundle up in 1 method. So long as that 1 thing doesnt exceed 70-80 lines I think its okay (especially if it's compact/dense code)
less lines doesn't mean better or more legible code..
Say what you guys want. The less your eyes have to move around the script the more readable it is. That's how it's always been in my experience. Short code is readable code.
thats like saying driving a car with a binocular is better than your own two eyes because is less for your brain to process ๐ค
Completely broken analogy
When trying to analyze a script it is simply easier to analyze less.
If the street was smaller, of course it's easier to drive.
some people can't read well LINQ and thats less lines, what are you talking about
less doesn't always mean better
Of course it doesn't always mean better
Nothing always means better
But in my expereince the shorter you can get a script down to, usually measured by lines, the easier it becomes to maintian because you are simply maintaining less.
Here's one of my scripts that handles weapon handling. Look at all of that well sectioned and "named" code that you don't need to jump around to find!
Ignore the fields
consider that you said "comes down what you consider 1 thing to be" and then you said "handling jump, move, and turning in a character controller is all a good thing to bundle up in 1 method"
messy
yeah, that "1 thing" is basic player body controls
There's a hard limit because sometimes you actually need methods for their intended purpose, to reduce duplicate code. So no, at some point you would have to divide it into sections.
Classes too
anyways your code really isnt readable either
so much to learn ๐ฅน
If I ever need to change something about recoil, I'll go to the big green line that says "Weapon Recoil" and change it
while you guys keep bickering about maintainability or something
"Go back to your code after 3 months and tell us if you understand anything" GDL said... those snobs.
At this point I think this is "agree to disagree", we both have different philosophies for how we see code, I use functions to separate logic in my code instead of comments, I can see your view, I just disagree with it, it would be a hinderance to code that way for me, simply because of how I see "1 method" differently than you do, but thats because my brain prefers to see separation of logic rather than one big thing and ive adapted to scanning code that way, I look for a "recoil" function or class rather than a comment containing the words "recoil" in it - its also nice having the ability to comment or condition a function rather than several lines, but we may just not see code the same way
Yeah, this is fair.
Anyways, a few pages ago I actually asked a question. Gonna bump it now, help would be appreciated.
I did competitive programming and we could do the entire program in a few lines with alphabetical variable naming. That is horrible for any team to work on.
idk if you have been in any coding team whatsoever
Have not. Code golf goes far beyond the reasonable assumption of what I mean by "short code" though.
I dont know the answer to your question, but just here to say I for one 100% agree with you on the code style stuff
Also a thing I noticed is that I also use implicit private modifiers and braces on the same line :D
This is an example of what happens when you make a method for everything (from a project I worked on with a team)
https://hatebin.com/vadfbffeja
i have a question, could you access a static varible from another script on another scene that havent be loaded?\
Yes
What no
your scripts have nothing to do with the scene. A static variable is associated with the type, not the instance
If the scene is not loaded you aint accessing shit from it
Static members always exist
static
okay, then it should be fine. Im transfering a list of data into a static list from another script in another scene. Just trying to make sure i could access it. Thank you then
whats the data? seems like an odd use case to need static here
My bad I jumped the gun here
Just make sure it isn't null. You cant initialize it from Awake or Start as they are not going to be called, so you have to do it like this:
public static List<...> ... = new List<...>();
Im creating a fishing minigame for an rpg game. Lets say there are many fish areas that have their own certain type of fish. I already have a list of fish in every areas accordingly, so every time the player click the fish area, those list will be transfered to the minigame script that has a static list variable to contain the previous fishes. Its for the reward ramdomizer
okay gotcha
as long as you're aware of how static works, you can make this work. it just may have some downsides that are annoying to debug. I would maybe go for a singleton instead so you can have a method that allows you to pass in a list and also startup the scene along with anything else thats needed. This way you can try to enforce what happens all in one place.
Not really much different, but it'd basically protect you from a friend (or yourself in the future) from changing the public static list when its not meant to be changed, and then wondering why the whole minigame stopped working
yeah, actually ive been thinking to make a singleton, but lets say some architectures from my lead programmer doesnt want me to do that hahaha (i know its weird)
If he doesnt want you using a singleton he will for sure not want you to use a unprotected static field in a class
yea weird, considering a singleton is basically just a static reference to the instance. the public static list is way worse
Must one of the people who saw online โSingleton Badโ and now just parrots this sentiment
i already think a way to protect it, no problem
a different way would be have a game manager. This creates the minigame manager (whatever you wanna call it). Then you create fishing areas, pass the minigame manager to a script on the fishing areas. On click, do whatever you need
Or make a scriptable object ๐
singletons are a much cleaner architecture than most static alternatives since you can control its lifetime between scenes
can anyone point me in the right direction to be able to save scriptable objects to json using newtonsoft
Okay, so I'm using
AudioSourceObj.volume = 0.01f, and even through debugging proving it is set to 0.01, it STILL. IS. 1!!
Can someone please help me figure out why is is reverting to one?
are you ever writing to scriptable objects
or is it readonly data
i am writing to them, using them as an inventory
- I have a transform and a vector3 that represents a local position within the transform. What is the most efficient way to get a matrix4x4 that ocrresponds to that position?
When I set the volume to 0 in script, it mutes it. It seems it can only be between 0 and 1
well, you'd tackle it like any other way you'd save data, but if you're appending data over some sort of defaults then you can just use the ID of the scriptable object and then write create a few structs to write the more unique data.
well doesnt the ID of the SO change so serializing that would be useless
you cant save references to SO's i thought
if you're using SOs and creating variations using the asset context menu, then you're creating different variations of defaults of the script. If you were to keep track of these by ID, you can probably save yourself from serializing more data than you need to, but you still need to serialize all the data in which you write to. An example would be writing to a weapon SO, you'd write the damage values if you are to modify them, but it's not likely to modify the sprite, so you might as well just load it from the SO.
just depends how you're using them is the question, but if you're using SOs to write data to, I'd assume you have some specific set already when making copies of it
otherwise you'd just use plain ol' c# scripts
is that what you want?
for simplicity i would just save using poco. I dont see why you would want SO in this case
do yo mean to just use transformpoint and create a 4x4 from that ?
what do you mean by POCO?
plain c# script
I just did it!
it works now!
ty for helping me
400 rooms!
neat, it would be nicer if you had multiple paths though
well, the number of paths solely depends on the chance of a big room spawning, which has 3 room connections, meaning itll spawn 3 rooms in different directions, if it has space
what I meant was, if you look at your map and select any 2 points on it there is always only one path between them
ohhh i see
but a damn good effort none the less
how could I give a scriptable object a unique guid that is assigned once and can not be changed?
unity assigns an asset ID to one, but you can just generate your own otherwise
Whats your use case where a SO might need a unique ID? Why might you not be able to use the SO itself? Assuming you likely would have unique SO's to begin with (for example, you probably wouldnt have 2 of the same weapon), or are you trying to generate SO's of a certain type with a editor script or something similar?
for saving and loading asset presets
Wouldnt you still be able to use the SO itself?
well, how would you write that to JSON and load from
you can either write by the path, or the easier way, an ID that's mapped to that path
Ah I see, in that case if the SO is being saved to JSON or something that isnt an asset in the project, then I can see generating a guid for each SO
when i read transform.localrotation.x it goes from 0-360 but in the inspector and also while setting it via "transform.localrotation.x" it's diffrent. when looking up it reads 270 but in the inspector it's -90. how do i read what the inspector's seeing?
When you create an SO instance from the asset context menu, you're creating a copy which you can define different values to, though it's not a different type. This makes serializing by type not the solution if that's what you're thinking of, but assuming you do want to write to the SOs and serialize all its data, then yes you can probably do that.
Though, the idea of IDing the SOs is that you're not always overwriting (personally I never write to SOs) the data in the SO, so why serialize data when you can just make a lookup for your SOs and load it from there?
Similarly to prefabs, you wouldn't serialize prefabs completely, you'd have a manager that handles the construction of these assets which is defined by IDs.
Local rotation is a quaternion. Assigning directly to the X component will not give you what you think. Anyways -90 and 270 are the same angle. You cannot read back this same because you give it euler, unity stores as quaternion, inspector shows it as euler so it must convert back. Sometimes it gives you a different set of angles but equaling the same rotation
so if i just read localrotation.x it'll show what it says in the inspector?
No because it is a quaternion
If you absolutely need to keep track of some euler angles, store your own version of them in the script and do your operations there. Using the .rotation will suffer from what I said about it being shown back as different values.
If you can work purely with quaternion it is better so you dont need to have your own local euler system going on
Right, I usually use SO's as "blueprints" so for example I might have a SO that creates weapons, but id likely not have 2 "glock 18"s, even if I have 2 "pistolSO", I can see if your trying to save a serialized class inside the SO to file file to load into a SO instance (weather you save that back as an asset or just use it at runtime) make sense, otherwise if the SO is already in your project assets, I agree having a lookup of some sort makes sense but I cant see a reason to save the SO in a different form/JSON/etc outside the project, maybe I misunderstood something there
I have a value that sets the x euler angle, when that value is -90 the camera looks up, but when i read the localrotation euler angles it's 270, I just need to read the localrotation so i can get that same measrement
How do you define between a glock 18 and another pistol that's also an instance pistolSO then?
unless you're writing all data from that SO type then deserializing it as a pistolSO then there wouldn't be ambiguity, but then you're required to update the whole base SO with those values
Did you miss my message above? I told you exactly why this happens and what to do about it
you really didn't
I did, if you didnt understand something then you can ask me to clarify. But reposting the question really isnt gonna get you a different answer
I have a feeling like you arent properly reading my messages. I said you can ask me to clarify
sorry it's really late and i've been coding all day
I applogise for being snarking
snarky
Anyways that alone is not a solution to the real issue at hand, I dont even think quaternion will return an euler value greater than 360
that solution works for my use cases tho
the rotation is clamped from -90 to 90
it's a fps camera thing
It's better if you just store the angle that it should be as I wrote here #archived-code-general message
Theres no point really assigning it to the rotation, having it convert to quaternion, converting it back to euler, sending it through this function, then getting the result. Compared to just storing it and already having what it should be
I'm manually rotating the camera in another script, so when i finish rotating it i need to know what i need to set the variable that's moving the camera in the fps controller
Though if it works then ๐คทโโ๏ธ carry on. I feel like there are edge cases where this might not work but I am too tired to think of an example right now
if there are edge cases, i'll cross that bridge when it comes to it
Maybe it depends on how the SO is used, I often use them like this:
[CreateAssetMenu(...)]
public class SomeSO : ScriptableObject
{
public SomeData data;
}
[System.Serializable]
public class SomeData
{
//pistol data, damage, ammo, etc...
}
For myself, I would be saving SomeData to JSON, and loading that into a SomeSO instance if I needed it, I personally have not tried saving the entire SO itself, though SomeSO in this case would be the "PistolSO" or "WeaponSO", etc
You can see the cases quickly if you manually assign rotations in inspector. I believe if you put (0, 180, 0), itll automatically give you back (180, 0, 180). I dont remember the exact case but it was something like that where you get back an equal rotation but widely different numbers
I'm not manually setting it in the inspector I'm manually setting it via "transform.localrotation = quaternion.eulerangles()"
Right, it depends on the requirements, but think of a game like maybe classic doom where your gun is always the same damage, same reload speed, same capacity. There you wouldn't care to serialize all that data beyond something like your current ammo (and the ID foremost).
I know, I was just saying you can quickly see the issue by doing it in inspector. It is the same by giving it euler values through code
Debug.Log("found UI");
{
UnityEngine.UIElements.Button button1 = new();
Debug.Log("create button 1");
button1.clicked += () => button1.text = "CLICKED";
Debug.Log("add clicked to button 1");
ui.rootVisualElement.Add(button1);
Debug.Log("add button 1 to ui");
}
{
UnityEngine.UIElements.Button button1 = new();
Debug.Log("create button 2");
button1.clicked += () => button1.text = "CLICKED";
Debug.Log("add clicked to button 2");
ui.rootVisualElement.Add(button1);
Debug.Log("add button 2 to ui");
}
Debug.Log("return");
[ now : 20:38:6:535] [ since last : 0:0:0:6 ] found UI
[ now : 20:38:6:551] [ since last : 0:0:0:16 ] create button 1
[ now : 20:38:6:552] [ since last : 0:0:0:1 ] add clicked to button 1
[ now : 20:38:6:554] [ since last : 0:0:0:2 ] add button 1 to ui
[ now : 20:38:6:555] [ since last : 0:0:0:1 ] create button 2
[ now : 20:38:6:557] [ since last : 0:0:0:1 ] add clicked to button 2
[ now : 20:38:6:558] [ since last : 0:0:0:1 ] add button 2 to ui
[ now : 20:38:6:559] [ since last : 0:0:0:1 ] return
[ now : 20:38:6:559] [ since last : 0:0:0:0 ] invoked queue action
Quaternions are on too high a level for my understanding lol, I'll just use Euler's in the meantime
what parts of this can be executed on a background thread ?
eg, gameObject property must be called on the main thread, but what else must be called on the main thread ?
Probably none.
And even if it could, you probably shouldn't.
why
i want to try to avoid getting stutters on the main thread when instantiating my ui
- There's no reason to.
- You don't wanna mess with threads too much.
- Overhead?
eg, can i build UI components in the background and then attach them to my scene on the main thread ?
I have some recollection of debugs not working on a background thread.
Debug.Log does work in any thread
Hmm... Must be fake memories then.
anyway can i do this ?
eg
RunOnBackground(() => {
// build UI in background
UnityEngine.UIElements.Button button1 = new();
UnityEngine.UIElements.Button button2 = new();
button1.clicked += () => button1.text = "CLICKED";
button2.clicked += () => button2.text = "CLICKED";
RunOnMain(() => {
// attach UI in foreground
ui.rootVisualElement.Add(button1);
ui.rootVisualElement.Add(button2);
});
});
I wouldn't be surprised if it's not possible, but you can try and see ๐คทโโ๏ธ
i doubt when you new a uielement you are interacting with the scene
Btw check if some calls are interacting with the scene not a strict test to indicate if the call can be called in background
As with anything Unity, it matters whether the implementation is interacting with the engine in a way that isn't thread-safe, which is a lot of the native APIs. Luckily UITK is implemented a lot more in managed land... But not all of it. So might have mixed results, and due to a lot being event based, it could trigger different things with minor changes
The answer is try it and see, and the longer answer is, even if it does work it doesn't sound robust to change
How do I find x,y position of a top/center sprite?
I am trying to use bounds, but I can't figure this out.
guys i cant do Input.GetAxis in non-monobehaviour scripts ?
Vector3 spriteTopPosition = CharacterSprite.bounds.center - CharacterSprite.bounds.extents;
//Vector2 newPos = Camera.main.WorldToScreenPoint(CharacterSprite.transform.position - spriteTopPosition);
Vector2 newPos = spriteTopPosition;
selectorInstance.transform.position = newPos;
its highlighted as error
Nvm had to add UnityEngine.
No the problem was that
it didnt tell me what was wrong
I mean it did
but not very obvious
sometimes the IDE will give you hints
depends on IDE i guess
or extensions
i use VSC coz it feels faster and less packed than VS
and its free unlike Rider or however it was named
oh I see, yeah probably not as much help as vs
public class ThreadRunner {
ConcurrentQueue<Action> currentFrame = new();
ConcurrentQueue<Action> nextFrame = new();
public void RunOnBackground(Action action) {
Task.Run(action);
}
public void RunOnMain(Action action) {
// the current action may repost itself to run each frame
nextFrame.Enqueue(action);
}
public void RunMainLoop() {
if (!nextFrame.IsEmpty) {
var tmp = currentFrame;
currentFrame = nextFrame;
nextFrame = tmp;
}
while (currentFrame.TryDequeue(out var action)) {
action();
}
}
}
would this do?
var tmp = currentFrame;
currentFrame = nextFrame;
nextFrame = currentFrame;
whoops
so confusing to read
// swap action buffers
var tmp = nextFrame;
nextFrame = currentFrame;
currentFrame = tmp;
this maybe ?
that would incur allocation overhead
this is correct
var tmp = currentFrame;
currentFrame = nextFrame;
nextFrame = tmp;
currentFrame should be empty at this point
so you swap an empty queue for a full one
i see 2 ways of doing this: 1. have some room models that loop around and stuff like that and 2. instead of not placing a room, make a procedural connection part that connects 2 rooms
but ill go with 1
what I would do is look to see if there is already a potential connecting room and limit the room generation so it gets a connection
true thats also something
but it prob wouldn't happen so often
unless yea i limit the generation
ill see
you're on the right track though, good proc gen is hard
and then comes the fun of doing it in real time
yea
// swap action buffers
var tmp = nextFrame; // full
nextFrame = currentFrame; // full = empty
currentFrame = tmp; // empty = full
exactly
also changed to
public void RunOnBackground(Action<object> action) {
Task.Run(() => action(action));
}
public void RunOnMain(Action<object> action) {
nextFrame.Enqueue(action);
}
public void RunOnMain(object action) => RunOnMain((Action<object>)action);
so we can do RunOnMain(r => RunOnMain(r)); // repeat every frame
RunOnBackground(r => RunOnBackground(r)); might be a bad idea tho, since doing such would basically be
while(true) {
Thread.run(() => {});
}
```which would probably be expensive and a thread pool may deadlock while adding a thread while running an existing thread if all threads happen to do so
T1 add T1 // thread 1 runs and re-adds itself to the pool
T2 add T2 // thread 2 runs and re-adds itself to the pool
deadlock, cannot add thread, capacity 2, active 2, both T1 and T2 cannot exit until a thread has been added, but a thread cannot be added until one has ended
still not sure what you hope to achieve with this
swapping the queue should be slightly faster then using one concurrency queue at all.....just little bit since the worker still need to process all the task at first but he dont need to get the lock when dequeue
yea
it also avoids endlessly running the same task
eg
we deque task 1
task 1 runs
task 1 queues itself
we deque task 1
...
why the task one can dequeue itself
but why? it seems like you are building a game engine within a game engine
a task may wish to run itself every frame for whatever reason, or tasks may wish to run other tasks
for example, a layout engine may need to postpone its layout until the next frame due to a change
idk
you worker should be
public void Enqueue()
private void Work(){
while(true){
if(queue.tryDqueue(out work)){
work();
}
}
}
```obviously the work can enqueue itself to the queue but it cannot call work() on your worker
btw this is simple consumer-producer model
i know
i have a silly code design problem, there are 2 approaches ive tried to a problem:
- put engine code on Engine Monobehaviour script, etc, reference engines etc from Car class
- create separate non-mono classes for engine functionalities like throttle etc and reference them from a car (instead of engine)
with 2. i can edit these things just when i have my car selected and i dont need to search for engine and other children in car transform hierarchy
its so much better to debug
but i think it shouldnt be like this, these variables should probably go to Engine since theyre engine related
I guess i can just put them in engine and make it all Serialized so that i can edit them from the main car script inspector
It probably would make most sense on the gameobject that's driving that specific instance
and for that it must be a mono
Ideally you'd have a Car script on the Mono too which includes an instance of Engine so this way you just need to have a reference to the Car to access Engine
In that case you wouldn't need Engine as a Mono since it's the Car script that's on the gameobject
So yeah, I believe it aligns with your number 2 suggestion
Unless you have a physical model for the engine (which could be damaged), then it could make sense for it to also be a mono
Anyone know how to work with AR?
Just wondering if anyone knows how to get the x position of my mouse click, when it clicks on an object that is scrollable?
My object is contained within a scrollrect, with a scrollbar controlling where we are on the timeline. When i click on a place on the object, I want the song time to skip to there, but how do I do that when I won't know where I am within the current bounds of the scrollbar?
hmmm for some reason my code isnt working o.o
[ now : 22:53:40:878] [ since last : 0:0:0:4 ] posting runnable
[ now : 22:53:40:888] [ since last : 0:0:0:9 ] posting runnable
[ now : 22:53:40:889] [ since last : 0:0:0:1 ] posting runnable
[ now : 22:53:40:890] [ since last : 0:0:0:0 ] posting runnable
[ now : 22:53:40:890] [ since last : 0:0:0:0 ] no new actions for this frame
[ now : 22:53:40:898] [ since last : 0:0:0:7 ] no new actions for this frame
[ now : 22:53:40:914] [ since last : 0:0:0:15 ] no new actions for this frame
[ now : 22:53:40:930] [ since last : 0:0:0:16 ] no new actions for this frame
[ now : 22:53:40:948] [ since last : 0:0:0:17 ] no new actions for this frame
[ now : 22:53:40:964] [ since last : 0:0:0:16 ] no new actions for this frame
Debug.Log("posting runnable");
tr.RunOnMain(() => {
Debug.Log("attaching ui");
// attach UI in foreground
ui.rootVisualElement.Add(button1);
ui.rootVisualElement.Add(button2);
});
public void RunOnMain(Action<object> action) {
if (Thread.CurrentThread == main) {
Debug.Log("running action on current thread");
action(action);
} else {
Debug.Log("posting action to next frame");
nextFrame.Enqueue(action);
}
}
shouldnt i have gotten at least a compile error ? o.o
welp i definitely get a compile error with this
(27,16): error CS1061: 'ScriptManager.ThreadRunner' does not contain a definition for 'aRunOnMain' and no accessible extension method 'aRunOnMain' accepting a first argument of type 'ScriptManager.ThreadRunner' could be found (are you missing a using directive or an assembly reference?)
so thats good
and what is aRunOnMain
is it possible to add attributes to a predefined unity class?
Like lets say I wanted to add an attribute to LineRenderer Called TargetPosition Could I do that?
you cannot directly add attributes to predefined classes
i assume by attribute you are actually referring to a property or variable. but the answer is no either way. at best you can create extension methods
public class ExtendedLineRenderer : MonoBehaviour
{
public Vector3 targetPosition;
private LineRenderer lineRenderer;
}
somight like that might work for you, depending of what will be the use case of targetPosition
yeah ok good to know
I had hoped there was some way to create extension attributes like extension methods
nope. and keep in mind this isn't java, attributes in c# are something different
I actually know c# better than I know java heh
or I like to think
maybe I mean properties?
either way, the game working does not hinge on this being a thing
I will just have to write some slightly messy code
you might be able to inherit from LineRenderer (i can't actually find it in the cs reference at the moment to check whether it is sealed or not). or just use some wrapper class that has those desired properties on it and manages the linerenderer component for you using those properties
you cannot inherit from LineRenderer
you cannot directly inherit from built-in Unity components -> they are all sealed
I'd just make a component that handles a LineRenderer for you
LineRendererWrangler
maybe pick a more specific name
they aren't all sealed. but i was able to find that LineRenderer is in fact one that is sealed
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Graphics/GraphicsRenderers.bindings.cs#L312
Excellent
working well enough
welp i dunno wat to do now
write code
i dunno wat i wanna write lol
functional code :3
Is it possible to input two buttons for 1 function ?? for example i have public string btndwn; Can i input two buttons in this ??
what do you mean
if you mean for something like Input.GetButton then no, you need a separate call for each button you want to query
if(Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.B){
Debug.log("Wowhua Two buttons are held");
}
like this?
oops forgor to close string
ya but i need to use Public string btname so that i can input btn name in inspecttor
oh you can just do Key I think
theres some Type you can put in the inspector to have a list of all the keys but I cant remember which one it is
if you are querying individual keys, then use a KeyCode rather than a string
void SetTargetPos(ref Vector3 TargPos){
TargPos = transform.position + Random.onUnitSphere;
}
Vector3 SetTargetPos2(){
return transform.position + Random.onUnitSphere;
}
is there any bearing on which of these two functions would be faster? presuming that the calculation to get the final TargPos will get more complex (raycasts and shtuff)
public string F_Pause_Game(){return Pause_Game;}```
now i wana input like two keys in the inspector how i do it ??
Get Functions ๐คข
dont like em
public KeyCode[] pauseKeys;
void Update() {
bool pausedPressed = pauseKeys.Any(key => Input.GetKeyDown(key));
}
also why are you using a Get function when the var is public anyways?
AAA Lambda jumpscare
I need to learn it better heh
thanks let me try this
ref makes me feel smarter I will use that
also something something memory allocation
there really is no reason that this needs to use ref. just return the value and assign to the variable at the calling site
the first one is much more confusing to me
I use out when I need to return a success/failure value and communicate a result
out is like extra return values right?
sorta?
like a return value
public bool TryGetThing(string thingKey, out Thing result) {
if (CanGetThing(thingKey))
{
result = FindThing(thingKey);
return true;
}
result = default;
return false;
}
I see out a lot more in other people's code snippets so maybe I should learn that one instead of ref
idk
back to code writing!
ref is inferior because:
- it doesn't assure that something is written to the variable
- it implies that the function might care about the variable's contents
ref means you can't do something like...
TryGetThing(string key, out var result);
if you tried to do this instead, you'd get a compile error because result isn't definitely assigned
TryGetThing(string key, ref var result);
hmmm interesting
well, it also might just be a compile error for some other reason
maybe you can't even declare a variable in a ref argument at all
but it'd be for the same fundamental reason
i'd assume that would be a compile error
oh it's definitely a compile error
void RecalcFeetPos(ref Vector3 EndPos){
Debug.Log("TryRecalcFeet");
var TryPoint = Physics2D.Raycast(transform.position, -(transform.position - (Conv0(transform.position+Random.insideUnitSphere))).normalized, FootLength, ground);
if(!TryPoint){
}
else{
EndPos = TryPoint.point;
}
}
but for this function I might prefer to use ref as it can be possible for the point to be null
can't let an uninitialized local variable escape like that (this is not about RecalcFeetPos; i was talking about my code above)
Vector3 can't be null.
This is a perfect application for returning bool and assigning an out parameter.
TryFindFootPosition
huh well this code works fine
gave me desired effect which is this
Not saying "oh my code is better you are wrong" more saying "this works for me I might keep it for now"
I would want to know the difference between "the point didn't change" and "I couldn't find a point at all"
but it's probably close enough
and how does this being a ref parameter instead of either a returned value or out param affect the calling code?
If the goal is to mutate a variable in place, then ref is fine. Try pattern is good for "returning result from an action that may or may not succeed"
I do rarely find myself needing to mutate a variable in place though.
well i think it keeps it from trying to assign the feetpos to null which as Fen stated is something that cannot be done
idk
if it ain't broke clearly there is no room for improvement (trust)
i'd like to see what you're doing at the call site because i'm sure your choice for making this a ref parameter is making you do some weird stuff there and that is also something you should consider when making choices like this
but also it's not preventing the variable from being assigned null because that is not possible at all anyway
what it is preventing is failing to assign to an out parameter
that would be a compile error, because out parameters must be definitely assigned
undefined != null
Vector3 what;
what is not null
feet[0].SetPosition(0, transform.position); feet[1].SetPosition(0, transform.position);
feet[2].SetPosition(0, transform.position);
//Debug.Log(Vector3.Distance(feet[0].GetPosition(0), feet[0].GetPosition(1)));
if(Vector3.Distance(transform.position, feet1Position) > FootLength){
RecalcFeetPos(ref feet1Position);
}
if(Vector3.Distance(transform.position, feet2Position) > FootLength){
RecalcFeetPos(ref feet2Position);
}
if(Vector3.Distance(transform.position, feet3Position) > FootLength){
RecalcFeetPos(ref feet3Position);
}
feet[0].SetPosition(1, Vector3.Lerp(feet[0].GetPosition(1), feet1Position, 0.08f)) ;
feet[1].SetPosition(1, Vector3.Lerp(feet[1].GetPosition(1), feet2Position, 0.08f)) ;
feet[2].SetPosition(1, Vector3.Lerp(feet[2].GetPosition(1), feet3Position, 0.08f)) ;
this is the feetcalc stuff
its somewhat messy
tbh I did not use out because I didn't consider it because I didn't really know how it worked
the west has fallen, billions must read documentation
theres just so many silly purple words
what's the problem?
it's just a sign that i've lost it :p
actually reading docs instead of blindly stumbling your way through code like a real programmer
absolutely, Rule #1 of programming, RTFM
You've lost the sauce?
Nice ๐
this is sarcasm for those of you unaware
ah, I just thought you had missed out the correct punctuation
or \s?
I don't really like tone indicators
you don't end a normal sentence with (sarcasm) when you are talking
but maybe thats just me having trauma from being overbellittled heh
'actually reading docs instead of blindly stumbling your way through code like a real programmer'
and
'actually reading docs, instead of blindly stumbling your way through code, like a real programmer'
say 2 completely different things, that is why punctuation exists
Hey guys could someone help me with getting OnParticleTrigger to work?
I checked the Triggers module on and all the options to callback.
But the OnParticleTrigger function doesn't actually trigger.
Hi guys,i would change the position of an object at the start method,but later it returns in the original position,do you know why?
We wouldn't know without more context but would probably assume that you've got something else changing the position or that you're changing the position of the wrong object.
Anyone experienced with OnParticleTrigger?
Have you read the instructions here? https://docs.unity3d.com/Manual/PartSysTriggersModule.html
Which object did you put that script on?
Hey, I put it on a child of a gameobject which has a particle system component.
Don't pay attention to the sphere collider attached, I was running out of ideas as to how to solve this ๐
You haven't actually added any triggers here
Wait, so what do I need to put there?
To begin, specify which Colliders in the Scene the particles can interact with. To do this, assign one or more Colliders to the Colliders list property. To increase the number of Colliders in the list, click the Add (+) button beneath the list of Colliders. To remove a Collider from the list, select the Collider and click the Remove (-) button. If you have not yet assigned a Collider to an index of the list, you can use the smaller Add (+) button, to the right of the empty entry, to create and assign a new Collider. This creates a new GameObject as a child of the Particle System and attaches a Sphere Collider
to it, then assigns the Collider to the empty entry.After you add the Colliders, you can then specify what a particle does when it meets the criteria for passing a particular trigger event type. There are four event types that describe how a particle can interact with a Collider
https://docs.unity3d.com/Manual/PartSysTriggersModule.html
Don't really get it, so I need to take every collider I want the particle system to collide with and drag it into the array?
yes
It can only interact with colliders in that list
Can I ask what you are actually trying to do with this stuff?
Hi, anyone familiar with terrain generation using Perlin Noise on a tilemap?
Is there a way to disable touch input (but keep the mouse input) from windows touch screen build?
I found only Input.simulateMouseWithTouches function in google, but that doesn't seem to do anything.
I have an ice attack coming up from the ground, from underneath the enemy.
The gameobject of the ice attack includes multiple children with all of them having a particle system attached to them. Each of the children is a different part of the overall particle system which make up the ice attack.
I want the child which has the particle system of the actual ice spikes, to collide with the enemy and fire an event once it does, I don't want the enemy to stop its movement when it collides with the ice. I want it to keep moving through the ice.
The enemy has a non trigger collider attached to it.
I don't want the ice to physically interact with the enemy, as I want to simply trigger an event when they do collide
I would just have the attack use some physics queries like Physics.OverlapSphere/Box/Capsule etc.
the particle system collision stuff is sketchy at best
or you want your children to have trigger colliders if the enemy has a rigidbody
I thought about it but the attack also goes forward as the spikes grow
Yeah the enemy also has a rigid body
then triggers on the children should do the job
seems like something that can be done pretty easily with a bunch of CapsuleCasts or OverlapCapsules
I thought about having an OnParticleCollider and just disabling the collider once it collides with the enemy, sort of a workaround
it looks something like this
https://www.youtube.com/watch?v=xd-hhJbyC7I&t=1s
9 Stylized Ice Attacks done entirely with Visual Effect Graph.
This package includes:
-9 Stylized Ice Attacks (3 customizable VFX Graphs)
-Highly Customizable (change texture, mesh, rate, color, size, etc. in the inspector)
-Textures (smoke flipbook, impacts, flares etc)
-Shaders (1 ice dissolve shader)
-HDRP and URP only
-Limited Mobile suppor...
Hey, is anyone familiar with perlin noise terrain generation on a 2D tilemap?
I am just wanting to set transition tiles between two biomes, I'm not looking for code but just general ideas on how to accomplish this. Is tileset rules a good idea?
If both objects need colliders but you aren't wanting physics interaction between them, perhaps you can just set them to not interact with each other?
https://docs.unity3d.com/Manual/LayerBasedCollision.html
damn, I haven't thought of that
Using particle colliders to produce actual gameplay effects sounds a bit flaky to me.
wait but if I set them to not interact through layers... wouldn't that mean I won't be able to discern if they collided at all?
How would you make it so for example an upwards ice attack like i've linked here would just hurt the enemy (who has a non-trigger collider).
By hurt I mean lower his health points variable
use a trigger collider or do a physics query
how would you use the trigger collider?
The ice attack comes froward and not all at once from underground
then i'd use several trigger colliders, or I would use OnTriggerStay and ignore enemies that aren't in range yet
as you describe it, put a trigger on each child
Problem is the ice spikes is one child and consists of all the spikes of the particle system.
I don't have access to each and every spike individually
'The gameobject of the ice attack includes multiple children with all of them having a particle system attached to them. Each of the children is a different part of the overall particle system which make up the ice attack' ?
Yeah, the ice attack particles consist of snow, sparks, ice spikes, wind, trails
All of them are different children
and you want to trigger them at different times of the attack?
Yes as they come out at different times
The attack comes out forward and upwards
so add a trigger to each child so you know when that particular type of effect has hit the enemy
I don't want to add to each child. I want to add it only to the ice spikes. But then I would have to play with the settings to get every trigger collider to match each of the spike's speed
The art of development is not doing what we want but what the game requires
this would be a mess of a script not a piece of art ๐
that would depend on you
you will probably create other attacks that move in a "wave" like that
figure out how to reliably detect hits once, then use that logic many times
In the start method i change the position of the object and it is the only time i change it
it is like it returns in the position of when the session starts
Show !code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Basically now i am trying to first put an object in the designed new posizion and then try to modify the position of the player
line 172 is when the object modify his position
Does that object have a CharacterController on it
but it is like it moves in the position i want and then it returns in the position of when it spawns
What is controllerPlayer
What type is the variable, and what object is it assigned to
a normal gameobject
like you can see the blue controller moves in the position i want but then it returns in the spawn position
Well the first thing I notice is a whole bunch of errors, any one of which could be causing code to halt execution
You should take care of those before you try to do any debugging
Holy red