Hey there. I’m fighting with a rather annoying jittering problem - which i don’t even understand.
I have a third person camera which has two modes. When in idle (as in no buttons pressed) it just follows the player. When you hold the left mouse button you can orbit around and with the right button i set the players rotation to that of the camera. Essentially the camera style of world of warcraft, in case you guys know that scheme.
Anyway. Now after having a lot of trouble with out of sync updates i’m finally at a point where everything works sort of okay. However i can’t figure out how to make the rotation behave.
I already moved the code to set the players rotation to that of the camera into the lateUpdate of the camera, and elimated that source of jittering. However, the other case, rotating the player via movement keys is supposed to stay in the rigidbody controller script (because that’s where all the keys are defined and what not).
I did achieve jitter free movement by setting the angularVelocity to my rotation speed in the FixedUpdate of the rigidbody controller script. However, that of course requieres that the rigidbody does not have its Y-Axis frozen. But it kind of needs to, because bad stuff will happen otherwise.
So i switched to setting the rotation directly via MoveRotation. And of course the jittering returned.
Now my question is… why ?
As i understand it FixedUpdate is called just before a physics step, and both are called before LateUpdate - so applying angularVelocity and setting the rotation directly should have the same result, shouldn’t it ?
I’m really struggling with this one, i seem to have a really hard time following what ever unity is doing. Don’t even get me started on all the problems with jittering i already fixed, without having the slightest clue what the hell i’m doing
AddTorque will effect the angularVelocity (it may consider mass as well if you use a ForceMode that does).
angularVelocity is the velocity at which the physics system will update the rotation of the gameobject the rigidbody is attached to.
By changing the rotation yourself, you’re side stepping this whole process.
It doesn’t work backwards either. It’s not that the angularVelocity is determined by the change in rotation. It’s that the rotation is determined by the angularVelocity. (Same goes for position and velocity, position is determined by velocity… NOT velocity determined by change in position).
FixedUpdate is not called in sync with Update/LateUpdate. This could be the source of your jitter, perhaps.
As for the title question, the difference between setting an angular velocity and setting the rotation is that one is an acceleration where the other is an immediate change. Velocity is applied over time. If a Rigidbody has a rotational velocity of (1, 0, 0) that means that it is rotating around the x axis at a rate of 1 radian per second (I think). On the other hand, setting its rotation immediately applies a new orientation regardless of what velocity is there.
This could potentially be the source of your jitter, especially in combination with any potential misunderstandings about the relationship between the fixed and variable update loops. If you’re directly setting positions then you probably don’t want to set velocity as well, as it will cause the position to change. If you’re doing one of those things in a variable loop and the other in the fixed loop then the “jitter” could be because one loop is moving it via velocity and then the other loop is snapping it to a specific position.
I do infact know the difference between velocity and just setting a position directly. I also know that both loops don’t run synchronous. When i said i used angularVelocity to rotate, i of course meant that i null it again next frame. Now, if i apply angularVelocity in fixedUpdate, then right after that the physics step applies this to the rotation. When i set the rotation myself, it’s done instantly, isn’t it ? So before the next lateUpdate everything should be set either way. However, one methode produces jittering, the other one doesn’t. And i don’t follow.