Hi!
I have a problem concerning Mecanim.
I’m making a 2D game (probably not relevant to the problem) and within this game the user moves a GameObject aligned to a Grid. Everything works perfect, but it looks a bit stiff, because I position the GameObject by setting the desired location via (example code)
transform.position += new Vector2(1, 0); // move right
transform.position -= new Vector2(1, 0); // move left
transform.position += new Vector2(0,1); // move up
// and so on
So I decided to make some animations (for moving to the left, right, up and down), that change the position of the GameObject (with Apply Root Motion, Root Motion Curves, Booleans and corresponding transitions) - again, works great in theory.
I wrote some code to handle the Animations that works as expected but: the GameObject isn’t moved completely in the desired direction.
For example:
Animation MoveLeft:
Keyframe 1 positions: X=0 and Y=0
Keyframe 2 positions: X=-1 and Y=0
The GameObject moves in the desired direction but only 0.9 units, sometimes less.
I can’t get it fixed but I guess, the animation isn’t played until the end when Unity switches back to an “idle state”, so that the GameObject doesn’t reach the desired position (1 full unit). Or am I missing something? I’m nearly at the point to leave it that stiff because I can’t get it to work as expected.
Every hint is more than welcome.
Best regards and thanks for reading.