mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
remove old
This commit is contained in:
parent
d197d2d87a
commit
1fb4f3c079
@ -428,139 +428,8 @@ void UpdateClient()
|
|||||||
Vector3 targetPosition = Vector3.Lerp(followStartPosition, predictionEndPosition, blendFactor);
|
Vector3 targetPosition = Vector3.Lerp(followStartPosition, predictionEndPosition, blendFactor);
|
||||||
Quaternion targetRotation = Quaternion.Slerp(followStartRotation, predictionEndRotation, blendFactor);
|
Quaternion targetRotation = Quaternion.Slerp(followStartRotation, predictionEndRotation, blendFactor);
|
||||||
|
|
||||||
// TODO
|
|
||||||
// one more adjustment.
|
|
||||||
// we never want to interpolate backwards.
|
|
||||||
// which could happen if our guess is still off.
|
|
||||||
|
|
||||||
|
|
||||||
// set position and rotation
|
// set position and rotation
|
||||||
tf.SetPositionAndRotation(targetPosition, targetRotation);
|
tf.SetPositionAndRotation(targetPosition, targetRotation);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// to where server state is going to be after blend time.
|
|
||||||
// blending anywhere else, no matter how smooth, would cause a
|
|
||||||
// final jump to the actual server position for FOLLOWING.
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/*
|
|
||||||
// DEBUG: force FOLLOW for now
|
|
||||||
// snapshot interpolation: get the interpolated remote position at this time.
|
|
||||||
// if there is no snapshot yet, just use lastReceived
|
|
||||||
Vector3 targetPosition = interpolated.position;
|
|
||||||
Quaternion targetRotation = interpolated.rotation;
|
|
||||||
|
|
||||||
// blend between local and remote position
|
|
||||||
// set debug color
|
|
||||||
// if (debugColors)
|
|
||||||
// {
|
|
||||||
// rend.material.color = blendingColor;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sample the blending curve to find out how much to blend right now
|
|
||||||
float blendingElapsed = (float)(NetworkTime.localTime - blendingStartTime);
|
|
||||||
float relativeElapsed = blendingElapsed / blendingTime;
|
|
||||||
float p = blendingCurve.Evaluate(relativeElapsed);
|
|
||||||
// Debug.Log($"{name} BLENDING @ {blendingElapsed:F2} / {blendingTime:F2} => {(p*100):F0}%");
|
|
||||||
|
|
||||||
// blend local position to remote position.
|
|
||||||
// getting both at once is fastest.
|
|
||||||
tf.GetPositionAndRotation(out Vector3 currentPosition, out Quaternion currentRotation);
|
|
||||||
|
|
||||||
// slow and simple version:
|
|
||||||
// float distance = Vector3.Distance(currentPosition, physicsPosition);
|
|
||||||
// if (distance > smoothFollowThreshold)
|
|
||||||
// faster version
|
|
||||||
Vector3 delta = targetPosition - currentPosition;
|
|
||||||
float sqrDistance = Vector3.SqrMagnitude(delta);
|
|
||||||
float distance = Mathf.Sqrt(sqrDistance);
|
|
||||||
|
|
||||||
// smoothly interpolate to the target position.
|
|
||||||
float positionStep = distance * p;
|
|
||||||
|
|
||||||
Vector3 newPosition = PredictedRigidbody.MoveTowardsCustom(
|
|
||||||
currentPosition,
|
|
||||||
targetPosition,
|
|
||||||
delta,
|
|
||||||
sqrDistance,
|
|
||||||
distance,
|
|
||||||
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, targetRotation, p).normalized;
|
|
||||||
|
|
||||||
// would the new position be ahead of us, or behind us?
|
|
||||||
Vector3 velocity = predictedRigidbody.velocity; // this is where we are going
|
|
||||||
|
|
||||||
// we slow down velocity while server state is behind us.
|
|
||||||
// if it slows down to zero then the 'isAhead' check won't work since it compares velocity.
|
|
||||||
// solution: always store the last valid velocity, and use that if needed.
|
|
||||||
if (velocity == Vector3.zero)
|
|
||||||
{
|
|
||||||
velocity = lastValidVelocity;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastValidVelocity = velocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 targetDelta = targetPosition - currentPosition; // this is where we would go
|
|
||||||
float dot = Vector3.Dot(velocity, targetDelta);
|
|
||||||
bool ahead = dot > 0; // true if the new position is ahead of us
|
|
||||||
// visualize 'ahead' for easier debugging
|
|
||||||
if (debugColors)
|
|
||||||
{
|
|
||||||
rend.material.color = ahead ? blendingAheadColor : blendingBehindColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the best possible smoothing depending on ahead / behind
|
|
||||||
// if ahead: interpolate towards remote state more and more
|
|
||||||
if (ahead)
|
|
||||||
{
|
|
||||||
// TODO reuse ApplySnapshot for consistency?
|
|
||||||
// tf.SetPositionAndRotation(newPosition, newRotation);
|
|
||||||
predictedRigidbody.MovePosition(newPosition); // smooth
|
|
||||||
predictedRigidbody.MoveRotation(newRotation); // smooth
|
|
||||||
}
|
|
||||||
// if behind: only slow down. never move backwards, as that would
|
|
||||||
// cause a highly noticable jitter effect!
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// slow down velocity, but always keep a minimum velocity of % of server velocity.
|
|
||||||
// coming to a hard stop would be too noticable.
|
|
||||||
// first, calculate delta between the two latest server states (if any)
|
|
||||||
Vector3 remoteVelocity = Vector3.zero;
|
|
||||||
if (clientSnapshots.Count >= 2)
|
|
||||||
{
|
|
||||||
NTSnapshot last = clientSnapshots.Values[clientSnapshots.Count - 1];
|
|
||||||
NTSnapshot secondLast = clientSnapshots.Values[clientSnapshots.Count - 2];
|
|
||||||
Vector3 lastDelta = last.position - secondLast.position;
|
|
||||||
float lastDeltaTime = (float)(last.remoteTime - secondLast.remoteTime);
|
|
||||||
if (lastDeltaTime > 0) remoteVelocity = lastDelta / lastDeltaTime;
|
|
||||||
}
|
|
||||||
Vector3 minimumVelocity = remoteVelocity * (1 - maximumSlowdownRatio);
|
|
||||||
Vector3 newVelocity = Vector3.MoveTowards(velocity, minimumVelocity, positionStep);
|
|
||||||
predictedRigidbody.velocity = newVelocity;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
// transition to FOLLOWING after blending is done.
|
|
||||||
// we could check 'if p >= 1' but if the user's curve never
|
|
||||||
// reaches a value of '1' then we would never transition.
|
|
||||||
// best to reach if elapsed time > blend time.
|
|
||||||
float blendingElapsed = (float)(NetworkTime.localTime - blendingStartTime);
|
|
||||||
if (blendingElapsed >= blendingTime)
|
|
||||||
{
|
|
||||||
// Debug.Log($"{name} END BLENDING");
|
|
||||||
BeginFollowing();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
// FOLLOWING sets Transform, which happens in Update().
|
// FOLLOWING sets Transform, which happens in Update().
|
||||||
else if (state == ForecastState.FOLLOWING)
|
else if (state == ForecastState.FOLLOWING)
|
||||||
|
Loading…
Reference in New Issue
Block a user