mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
blend better
This commit is contained in:
parent
08dabf0faf
commit
e88f88f4c1
@ -214,18 +214,21 @@ void UpdateClient()
|
||||
tf.GetPositionAndRotation(out Vector3 currentPosition, out Quaternion currentRotation); // faster than tf.position + tf.rotation
|
||||
float distance = Vector3.Distance(currentPosition, lastReceivedState.position);
|
||||
|
||||
// perf: only access deltaTime once
|
||||
float deltaTime = Time.deltaTime;
|
||||
|
||||
// smoothly interpolate to the target position.
|
||||
// speed relative to how far away we are.
|
||||
// => speed increases by distance² because the further away, the
|
||||
// sooner we need to catch the fuck up
|
||||
// float positionStep = (distance * distance) * interpolationSpeed;
|
||||
float positionStep = distance * positionBlendingSpeed;
|
||||
float positionStep = distance * positionBlendingSpeed * deltaTime;
|
||||
Vector3 newPosition = Vector3.MoveTowards(currentPosition, lastReceivedState.position, positionStep);
|
||||
|
||||
// smoothly interpolate to the target rotation.
|
||||
// Quaternion.RotateTowards doesn't seem to work at all, so let's use SLerp.
|
||||
// Quaternions always need to be normalized in order to be a valid rotation after operations
|
||||
Quaternion newRotation = Quaternion.Slerp(currentRotation, lastReceivedState.rotation, rotationBlendingSpeed * Time.deltaTime).normalized;
|
||||
Quaternion newRotation = Quaternion.Slerp(currentRotation, lastReceivedState.rotation, rotationBlendingSpeed * deltaTime).normalized;
|
||||
|
||||
// debug draw the blending data.
|
||||
// server state is drawn in OnGizmos
|
||||
|
Loading…
Reference in New Issue
Block a user