- Home /
The question is answered, right answer was accepted
Problems with rotating an object using angular velocity.
I'm trying to rotate a networked object by calculating the angular velocity on the client that is required to rotate the object to the same rotation as the server.
It all works fine however, when it reaches a certain rotation (supposedly Quaternion.identity?) it starts spinning in the opposite direction to its target.
We get a worldrotation from the server from which we calculate the deltarotation.
Quaternion deltaRotation = serverrotation * Quaternion.Inverse(myRigidBody.rotation);
Then we calculate the angle between the current rotation and the target rotation
float angle = 0.0f;
Vector3 axis = Vector3.zero;
deltaRotation.ToAngleAxis(out angle, out axis);
angle *= Mathf.Deg2Rad;
We calculate the angular velocity Vector3 angularVelocity = axis * angle;
We apply the angular velocity to the rigidbody
myRigidBody.angularVelocity = angularVelocity;
Answer by CrimSilk · Jul 26, 2018 at 10:48 AM
Okay I managed to solve it. Apparently the above code snippet is correct. But the network component converts the Quaternion to Euler angles before sending it. This caused a Gimbal lock.
So now I send the Quaternion directly and it is solved.
So for anyone that wants to rotate an object to another object using angular velocity.. Above code snippet should do the job ^^
Answer by Bystander333 · Jul 25, 2018 at 07:47 PM
Did you try using SLERP and some kind of extrapolation of time till the next server message?