mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Better CalculateAngularVelocity
This commit is contained in:
parent
80f2d1e641
commit
e93e2eae4d
@ -148,13 +148,26 @@ protected virtual void Update()
|
||||
|
||||
// Update velocity and angular velocity
|
||||
velocity = (pos - lastPosition) / Time.deltaTime;
|
||||
angularVelocity = (rot.eulerAngles - lastRotation.eulerAngles) / Time.deltaTime;
|
||||
CalculateAngularVelocity(rot);
|
||||
|
||||
// Update last position and rotation
|
||||
lastPosition = pos;
|
||||
lastRotation = rot;
|
||||
}
|
||||
|
||||
void CalculateAngularVelocity(Quaternion currentRot)
|
||||
{
|
||||
// calculate angle between two rotations
|
||||
Quaternion deltaRotation = currentRot * Quaternion.Inverse(lastRotation);
|
||||
|
||||
// convert to angle axis
|
||||
deltaRotation.ToAngleAxis(out float angle, out Vector3 axis);
|
||||
|
||||
// we assume the angle is always the shortest path
|
||||
// we don't need to check for 360 degree rotations
|
||||
angularVelocity = axis * angle * Mathf.Deg2Rad / Time.deltaTime;
|
||||
}
|
||||
|
||||
// snapshot functions //////////////////////////////////////////////////
|
||||
// get local/world position
|
||||
protected virtual Vector3 GetPosition() =>
|
||||
|
Loading…
Reference in New Issue
Block a user