Odd problem where all entities speed is intermittently sluggish.

Hello,

I’m pretty new to Unity, I’m following the Ruby’s Adventure tutorial.

I have a public variable set for speed on my character and enemies. They will move as intended at the correct speed, but once I make a change of any kind to the project then they all move incredibly slow. When this is happening, whether speed is set to 5 or 500, they move at the same speed while the game is running.

This is temporarily fixed if I check and un-check a freeze rotation box in one of the rigidbody components, but then everything goes back to slow behavior once I make another change in the project.

Since this is happening for all entities, I am worried it has to do with the Unity Engine rather than one of the objects I created. Perhaps there is a setting I’m not aware of, the tutorial I’m following uses an older version of Unity and I have already had issues with some inconsistencies.

I included an image of my character script as well as a shot of the inspector.

Is your framerate being impacted? Open up the stats window and see if it is likewise really low. If so you probably have some calc running amok and eating up lots of processing time.

Strangely my framerate is unaffected. Character/enemy animations are also moving at the normal framerate.

5835304--619021--stats.png

The only thing I noticed is that you’re doing a Rigidbody2D.MovePosition command per-frame which is only actioned when the simulation runs which by default is during the fixed-update. You’re also calculating the move based upon a scaling of the frame-time (not the fixed-update time) which is going to give you odd results if you’re not running the simulation per-frame.

If you have 10 render frames (Update) per simulation step (assuming FixedUpdate) then you’ll issue 10 moves but only the last one will happen and it’ll only be be scaling by that frames time.

If you’re moving at a fixed update rate then you need to issue a single move at that rate.

Thanks, the tutorial did not teach me about the FixedUpdate function. Very useful!