Horizontal movement animation and strange reaction to code

Just after “completing” the horizontal movement segment of the course and for some reason my character was rotating while moving left/right. I attempted to resolve this by locking my player z axis(rotate) but obviously thats not ideal. Not sure if this gives a hint but my running animation is not working either. Looking at the animator panel the player is just in a continuous state of idling. Also when attempting the flipping section the character shrinks.

transform.localScale = new Vector2 (Mathf.Sign(myRigidBody.velocity.x), 1f);

Any help would be greatly appreciated, have rewatched the same 4 videos numerous times now but cannot spot where I’m going wrong!


Welcome to our community! :slight_smile:

Do you remember what we did with our game objects (defenders and attackers) in Glitch Garden? Do the same here: Move the player’s parent game object via code and animate the child only. The child game object is supposed to have the Sprite Renderer attached.

It might be that you are currently experiencing a conflict between the animation and the code because both try to modify the same game object.

Hi Nina,

That didnt actually solve my problem at all because none of the child parent relationships are explained during this section of the tutorial. I can’t understand what you’re trying to say in your answer. I went back through the garden game and nothing is done differently.

What do you mean by “this section”? The child-parent relationship was covered in the Glitch Garden section but Rick didn’t use that approach in the TileVania project. Rick explained the concept in detail in lecture “Completing Animation Challenge” (currently #147 on Udemy) in the GlitchGarden section.

You will see that all defenders and attackers in GlitchGarden have got a parent and a child (Body) whilst the Player in TileVania has not. What I suggested was: Give the player a “Body” and animate that body, and move only the parent (“Player”) via code.

I hope this makes more sense now. :slight_smile: