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;