mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
ahead-detection & visualization
This commit is contained in:
parent
285a645b7e
commit
83ffaffb45
@ -68,7 +68,8 @@ enum ForecastState
|
|||||||
public bool debugColors = false;
|
public bool debugColors = false;
|
||||||
Color originalColor = Color.white;
|
Color originalColor = Color.white;
|
||||||
public Color predictingColor = Color.green;
|
public Color predictingColor = Color.green;
|
||||||
public Color blendingColor = Color.yellow; // when actually interpolating towards a blend in front of us
|
public Color blendingAheadColor = Color.yellow; // when actually interpolating towards a blend in front of us
|
||||||
|
public Color blendingBehindColor = Color.red; // when actually interpolating towards a blend in front of us
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
@ -212,8 +213,11 @@ protected override void Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3 lastSetPosition = Vector3.zero;
|
Vector3 lastSetPosition = Vector3.zero;
|
||||||
|
Vector3 interpolatedPosition = Vector3.zero;
|
||||||
protected override void ApplySnapshot(NTSnapshot interpolated)
|
protected override void ApplySnapshot(NTSnapshot interpolated)
|
||||||
{
|
{
|
||||||
|
interpolatedPosition = interpolated.position;
|
||||||
|
|
||||||
// ignore server snapshots while simulating physics
|
// ignore server snapshots while simulating physics
|
||||||
if (state == ForecastState.PREDICTING)
|
if (state == ForecastState.PREDICTING)
|
||||||
{
|
{
|
||||||
@ -229,10 +233,10 @@ protected override void ApplySnapshot(NTSnapshot interpolated)
|
|||||||
|
|
||||||
// blend between local and remote position
|
// blend between local and remote position
|
||||||
// set debug color
|
// set debug color
|
||||||
if (debugColors)
|
// if (debugColors)
|
||||||
{
|
// {
|
||||||
rend.material.color = blendingColor;
|
// rend.material.color = blendingColor;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// sample the blending curve to find out how much to blend right now
|
// sample the blending curve to find out how much to blend right now
|
||||||
float blendingElapsed = (float)(NetworkTime.localTime - blendingStartTime);
|
float blendingElapsed = (float)(NetworkTime.localTime - blendingStartTime);
|
||||||
@ -268,9 +272,21 @@ protected override void ApplySnapshot(NTSnapshot interpolated)
|
|||||||
// Quaternions always need to be normalized in order to be a valid rotation after operations
|
// Quaternions always need to be normalized in order to be a valid rotation after operations
|
||||||
Quaternion newRotation = Quaternion.Slerp(currentRotation, targetRotation, p).normalized;
|
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
|
||||||
|
Vector3 targetDelta = targetPosition - currentPosition; // this is where we would go
|
||||||
|
float dot = Vector3.Dot(velocity, targetDelta);
|
||||||
|
bool ahead = dot > 0;
|
||||||
|
// if (!ahead) return;
|
||||||
|
// visualize 'ahead'
|
||||||
|
if (debugColors)
|
||||||
|
{
|
||||||
|
rend.material.color = ahead ? blendingAheadColor : blendingBehindColor;
|
||||||
|
}
|
||||||
|
|
||||||
// assign position and rotation together. faster than accessing manually.
|
// assign position and rotation together. faster than accessing manually.
|
||||||
// TODO reuse ApplySnapshot for consistency?
|
// TODO reuse ApplySnapshot for consistency?
|
||||||
tf.SetPositionAndRotation(newPosition, newRotation);
|
//tf.SetPositionAndRotation(newPosition, newRotation);
|
||||||
//predictedRigidbody.MovePosition(newPosition); // smooth
|
//predictedRigidbody.MovePosition(newPosition); // smooth
|
||||||
//predictedRigidbody.MoveRotation(newRotation); // smooth
|
//predictedRigidbody.MoveRotation(newRotation); // smooth
|
||||||
}
|
}
|
||||||
@ -284,10 +300,10 @@ protected override void ApplySnapshot(NTSnapshot interpolated)
|
|||||||
if (Vector3.Distance(interpolated.position, lastSetPosition) >= epsilon)
|
if (Vector3.Distance(interpolated.position, lastSetPosition) >= epsilon)
|
||||||
{
|
{
|
||||||
base.ApplySnapshot(interpolated);
|
base.ApplySnapshot(interpolated);
|
||||||
lastSetPosition = interpolated.position;
|
|
||||||
}
|
}
|
||||||
// END CUSTOM CHANGE
|
// END CUSTOM CHANGE
|
||||||
}
|
}
|
||||||
|
lastSetPosition = interpolated.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prediction uses a Rigidbody, which needs to be moved in FixedUpdate() even while kinematic.
|
// Prediction uses a Rigidbody, which needs to be moved in FixedUpdate() even while kinematic.
|
||||||
@ -372,6 +388,12 @@ void OnCollisionEnter(Collision collision)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private void OnDrawGizmos()
|
||||||
|
{
|
||||||
|
Bounds bounds = GetComponent<Collider>().bounds;
|
||||||
|
Gizmos.DrawWireCube(interpolatedPosition,bounds.size );
|
||||||
|
}
|
||||||
|
|
||||||
// optional user callbacks, in case people need to know about events.
|
// optional user callbacks, in case people need to know about events.
|
||||||
protected virtual void OnBeginPrediction() {}
|
protected virtual void OnBeginPrediction() {}
|
||||||
protected virtual void OnBeginBlending() {}
|
protected virtual void OnBeginBlending() {}
|
||||||
|
@ -164,6 +164,30 @@ MonoBehaviour:
|
|||||||
syncDirection: 0
|
syncDirection: 0
|
||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0
|
syncInterval: 0
|
||||||
|
target: {fileID: 3429911415116987812}
|
||||||
|
clientAuthority: 0
|
||||||
|
sendRate: 30
|
||||||
|
bufferTimeMultiplier: 2
|
||||||
|
bufferSizeLimit: 64
|
||||||
|
catchupNegativeThreshold: -1
|
||||||
|
catchupPositiveThreshold: 1
|
||||||
|
catchupSpeed: 0.009999999776482582
|
||||||
|
slowdownSpeed: 0.009999999776482582
|
||||||
|
driftEmaDuration: 1
|
||||||
|
dynamicAdjustment: 1
|
||||||
|
dynamicAdjustmentTolerance: 1
|
||||||
|
deliveryTimeEmaDuration: 2
|
||||||
|
onlySyncOnChange: 1
|
||||||
|
bufferResetMultiplier: 5
|
||||||
|
positionSensitivity: 0.01
|
||||||
|
rotationSensitivity: 0.01
|
||||||
|
scaleSensitivity: 0.01
|
||||||
|
syncPosition: 1
|
||||||
|
syncRotation: 1
|
||||||
|
syncScale: 0
|
||||||
|
showGizmos: 0
|
||||||
|
showOverlay: 0
|
||||||
|
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||||
predictedRigidbody: {fileID: -177125271246800426}
|
predictedRigidbody: {fileID: -177125271246800426}
|
||||||
blendingRttMultiplier: 2
|
blendingRttMultiplier: 2
|
||||||
blendingCurve:
|
blendingCurve:
|
||||||
@ -199,19 +223,12 @@ MonoBehaviour:
|
|||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
localForceDampening: 0.2
|
localForceDampening: 0.5
|
||||||
motionSmoothingVelocityThreshold: 0.1
|
collisionChaining: 1
|
||||||
motionSmoothingAngularVelocityThreshold: 5
|
maxCollisionChainingDepth: 2
|
||||||
motionSmoothingTimeTolerance: 0.5
|
velocitySensitivity: 0.1
|
||||||
stateHistoryLimit: 32
|
angularVelocitySensitivity: 5
|
||||||
recordInterval: 0.05
|
|
||||||
onlyRecordChanges: 1
|
|
||||||
compareLastFirst: 1
|
|
||||||
positionCorrectionThreshold: 0.1
|
|
||||||
rotationCorrectionThreshold: 5
|
|
||||||
oneFrameAhead: 1
|
|
||||||
snapThreshold: 2
|
|
||||||
reduceSendsWhileIdle: 1
|
|
||||||
debugColors: 1
|
debugColors: 1
|
||||||
predictingColor: {r: 0, g: 1, b: 0, a: 1}
|
predictingColor: {r: 0, g: 1, b: 0, a: 1}
|
||||||
blendingColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
blendingAheadColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||||
|
blendingBehindColor: {r: 1, g: 0, b: 0, a: 1}
|
||||||
|
@ -301,6 +301,30 @@ MonoBehaviour:
|
|||||||
syncDirection: 0
|
syncDirection: 0
|
||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0
|
syncInterval: 0
|
||||||
|
target: {fileID: 3429911415116987812}
|
||||||
|
clientAuthority: 0
|
||||||
|
sendRate: 30
|
||||||
|
bufferTimeMultiplier: 2
|
||||||
|
bufferSizeLimit: 64
|
||||||
|
catchupNegativeThreshold: -1
|
||||||
|
catchupPositiveThreshold: 1
|
||||||
|
catchupSpeed: 0.009999999776482582
|
||||||
|
slowdownSpeed: 0.009999999776482582
|
||||||
|
driftEmaDuration: 1
|
||||||
|
dynamicAdjustment: 1
|
||||||
|
dynamicAdjustmentTolerance: 1
|
||||||
|
deliveryTimeEmaDuration: 2
|
||||||
|
onlySyncOnChange: 1
|
||||||
|
bufferResetMultiplier: 5
|
||||||
|
positionSensitivity: 0.01
|
||||||
|
rotationSensitivity: 0.01
|
||||||
|
scaleSensitivity: 0.01
|
||||||
|
syncPosition: 1
|
||||||
|
syncRotation: 1
|
||||||
|
syncScale: 0
|
||||||
|
showGizmos: 0
|
||||||
|
showOverlay: 0
|
||||||
|
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||||
predictedRigidbody: {fileID: 1848203816128897140}
|
predictedRigidbody: {fileID: 1848203816128897140}
|
||||||
blendingRttMultiplier: 2
|
blendingRttMultiplier: 2
|
||||||
blendingCurve:
|
blendingCurve:
|
||||||
@ -336,19 +360,12 @@ MonoBehaviour:
|
|||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
localForceDampening: 0.2
|
localForceDampening: 0.5
|
||||||
motionSmoothingVelocityThreshold: 0.1
|
collisionChaining: 1
|
||||||
motionSmoothingAngularVelocityThreshold: 5
|
maxCollisionChainingDepth: 2
|
||||||
motionSmoothingTimeTolerance: 0.5
|
velocitySensitivity: 0.1
|
||||||
stateHistoryLimit: 32
|
angularVelocitySensitivity: 5
|
||||||
recordInterval: 0.05
|
|
||||||
onlyRecordChanges: 1
|
|
||||||
compareLastFirst: 1
|
|
||||||
positionCorrectionThreshold: 0.1
|
|
||||||
rotationCorrectionThreshold: 5
|
|
||||||
oneFrameAhead: 1
|
|
||||||
snapThreshold: 2
|
|
||||||
reduceSendsWhileIdle: 1
|
|
||||||
debugColors: 1
|
debugColors: 1
|
||||||
predictingColor: {r: 0, g: 1, b: 0, a: 1}
|
predictingColor: {r: 0, g: 1, b: 0, a: 1}
|
||||||
blendingColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
blendingAheadColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
|
||||||
|
blendingBehindColor: {r: 1, g: 0, b: 0, a: 1}
|
||||||
|
Loading…
Reference in New Issue
Block a user