Prediction: only set velocity if not kinematic

This commit is contained in:
mischa 2024-02-14 10:41:14 +01:00 committed by MrGadget
parent 54c8caac54
commit e7c8898679
2 changed files with 20 additions and 7 deletions

View File

@ -495,8 +495,12 @@ void ApplyState(double timestamp, Vector3 position, Quaternion rotation, Vector3
// to stop and start moving again on client - slide as well here.
predictedRigidbody.position = position;
predictedRigidbody.rotation = rotation;
predictedRigidbody.velocity = velocity;
predictedRigidbody.angularVelocity = angularVelocity;
// projects may keep Rigidbodies as kinematic sometimes. in that case, setting velocity would log an error
if (!predictedRigidbody.isKinematic)
{
predictedRigidbody.velocity = velocity;
predictedRigidbody.angularVelocity = angularVelocity;
}
// clear history and insert the exact state we just applied.
// this makes future corrections more accurate.
@ -536,9 +540,13 @@ void ApplyState(double timestamp, Vector3 position, Quaternion rotation, Vector3
predictedRigidbody.rotation = rotation;
}
// there's only one way to set velocity
predictedRigidbody.velocity = velocity;
predictedRigidbody.angularVelocity = angularVelocity;
// there's only one way to set velocity.
// (projects may keep Rigidbodies as kinematic sometimes. in that case, setting velocity would log an error)
if (!predictedRigidbody.isKinematic)
{
predictedRigidbody.velocity = velocity;
predictedRigidbody.angularVelocity = angularVelocity;
}
}
// process a received server state.

View File

@ -23,7 +23,6 @@ public static void MoveRigidbody(GameObject source, GameObject destination)
rigidbodyCopy.mass = original.mass;
rigidbodyCopy.drag = original.drag;
rigidbodyCopy.angularDrag = original.angularDrag;
rigidbodyCopy.angularVelocity = original.angularVelocity;
rigidbodyCopy.useGravity = original.useGravity;
rigidbodyCopy.isKinematic = original.isKinematic;
rigidbodyCopy.interpolation = original.interpolation;
@ -33,7 +32,13 @@ public static void MoveRigidbody(GameObject source, GameObject destination)
rigidbodyCopy.freezeRotation = original.freezeRotation;
rigidbodyCopy.position = original.position;
rigidbodyCopy.rotation = original.rotation;
rigidbodyCopy.velocity = original.velocity;
// projects may keep Rigidbodies as kinematic sometimes. in that case, setting velocity would log an error
if (!original.isKinematic)
{
rigidbodyCopy.velocity = original.velocity;
rigidbodyCopy.angularVelocity = original.angularVelocity;
}
// destroy original
GameObject.Destroy(original);