Horizontal Player Movement section of C++ Udemy course

Hello,

I’m having trouble getting the myRigidbody.velocity section of this course to function as in the video. I’ve hand written the code, and copy pasted from the git and no matter what I do I can’t get the sprite moving horizontally. The key inputs are functioning as it is sending debug logs, I can also get the jump function to work AND the animations to switch the isRunning bool on (currently not off, not sure what’s up with that. may be a by product of not being able to move the x axis). Is there a setting I’m potentially missing and should look into? Or would it be something related to the code itself?

Any help would be greatly appreciated.
Thank you!

Hi Natthiad,

Welcome to our community! :slight_smile:

Just to ensure there is no misunderstanding: In this course, we use C#, not C++. Unity works with C#. I’m mentioning this because, in our Unreal courses, we use C++. Unity is not Unreal, though.

Regarding the problem with the movement, where did you place the Debug.Logs? And does the velocity value change as expected? If so, check if your movement component is attached to the correct game object.

If it is, disable the Animator, so the player is not controlled by the Animator anymore. Then test your game. If the player moves, the problem might be in the animation. A typical reason for animated objects that cannot be moved via user input is that the animation animates the position of the game object. In this game, Rick “animates” the SpriteRenderer only meaning his animation replaces pictures in the SpriteRenderer. He does not animate the player’s Transform.

Without knowing any details about your project and without seeing any screenshots, this is just a guess, though. Please let me know if this helped and/or if you were able to narrow the problem down further but cannot solve it yet. :slight_smile:


See also:



Hey so it does seem to be a problem with the Animator, I disabled it and was able to move the player sprite around the map on the X axis, the y axis is functioning as well.
I’ve attached some pictures of my script and components currently attached to my player model, and I went through again to try and see what would be the issue in the code, if I had something mistyped or something to that effect but I can’t seem to see where the issue stems from with the Animator being in charge. Am I missing something in the hierarchy? Or do you need some of the components to be unrolled to see what’s attached to what?

Thanks for the help in at least finding out the root cause.

Could you please open the animations? Then take a look at the left side in the Animation window. The player’s Transform must not be animated. Maybe you inadvertendly moved the player at some point while the Unity was recording. That can easily happen and is not noticeable immediately. Or maybe you did that on purpose but wasn’t aware that the animation would override the values that are getting applied by your code while the game is running.

Privacy & Terms