Fast rotation (120289)

I try to rotate a rigidbody. Rotation for slow speeds work just fine, but if i want to rotate faster a have a problem, that Quaternions only work from 0-360°, but if I like to use a speed that needs 2 or 3 rotation per calculation it does not work in right way.
Here is my code:

var anglePerSecond = Controller.SpeedInMs * 360.0f / (2.0f * this.transform.localScale.x * (float)Math.PI);
var q = Quaternion.Euler(0.0f, -anglePerSecond * Time.deltaTime, 0.0f);
rigidbody.MoveRotation(rigidbody.rotation * q);

Thanks for helping

Ugly problem, and I cannot think of a fix. You'll run into issues any time your frame-to-frame rotation is greater than 180 degrees. Assuming you are calculating this in FixedUpdate(), one way to mitigate the issue would be to decrease the FixedTimestep. This will increase the load placed on your game by the physics engine, but reduce the chance of a frame-to-frame rotation greater than 180 degrees.

–

1 Answer

1

The solution that @robertbu provided has worked for me in the past
In order to decrease the physics time step go to edit > project settings > time and then change your time scale

You could also put the code for the rotation in the FixedUpdate() function then change your fixed timestep this will allow the rest of your game to run normally but the fixedupdate and thus the rotation calculation would happen much more often.
Fixedtimestp can be editted in the same place as timescale