I am creating a 2D game and the enemies in the game have rigid body 2D connected to them.
I have not worked on the game for almost a year and when I started coding again I was forced to update Unity to the latest version (because I had upgraded iOS on my Mac).
An unexpected bug appeared. When I change direction of my enemies through a script the animation/animator changes its y position. I suspect changing localScale.x with -1 also affects the position of the animation/animator.
The enemies in my game are flipping when OnCollisionEnter2D is called.
Vector3 enemyScale = transform.localScale;
enemyScale.x *= -1;
transform.localScale = enemyScale;
It’s only when enemyScale.x == -1 that the animation/animators Y-position is off. As soon as OnCollisionEnter2D is called a second time and the enemy returns to it’s original localScale the animation/animator jumps back to it’s correct Y-position.
Anybody else who have encountered this problem?
It’s seems like the root position of the Animator is changing. Still not closer any solution.
Any help would be grateful.