Hi all
Unity 2D game. Working on an NPC.
I've got a question regarding just how instant the SetLookDirection function is in Char. Directly after this I am running a custom action that relies on the character being in a particular direction. That direction is Left. The NPC's default position is Up, as all characters are.
In the code first I run the SetLookDirection function, which should change the character's direction to left (Vector3(-1, 0, 0)). The line underneath this is the GetSpriteDirectionInt function, which should now be 1 (Left). But instead I am getting 3 (Up).
Does the SetLookDirection function not change the direction immediately, but just change some variables that get read on the next _LateUpdate call? Or in other words, does the character's direction only actually change on the next frame in _LateUpdate where the code that gets run in that single action (following the SetLookDirection function call) is called first?
Hope that makes sense. It's a bit confusing.
Comments
However, since both of these functions are public on the Char script, you should be able to simply call these after the SetLookDirection to force the change that frame.
When Custom, a character has no concept of direction, it'll just play whatever animation you tell it. If you want to change a character's direction, make sure their charState is set back to Idle.
The reason direction matters for me is because my 2d character's Sprite child gameobject changes according to the direction the character is facing. I am using spine animations and my specific animations sit within each direction data, so it's dependent on the direction being set. A bit hard to explain technically without examples, but it doesn't really matter - the point is I am using character directions not just for idle or walk facing, but also other custom animations.
I will change the direction right before the charstate changes to Custom, but moving on is there a way we could change it so that directions can be changed even when the charstate is Custom and not Idle?