set rigidbody in fixedupdate

This commit is contained in:
mischa 2024-04-03 18:46:52 +08:00
parent 4a8ad22412
commit 6330adf092

View File

@ -226,6 +226,32 @@ void UpdateClient()
}
}
else if (state == ForecastState.BLENDING)
{
// BLENDING sets Rigidbody which happens in FixedUpdate()!
}
else if (state == ForecastState.FOLLOWING)
{
// hard set position & rotation.
// TODO snapshot interpolation
tf.SetPositionAndRotation(lastReceivedState.position, lastReceivedState.rotation);
}
}
void Update()
{
if (isServer) UpdateServer();
if (isClientOnly) UpdateClient();
}
void FixedUpdateClient()
{
// physics movements need to be done in FixedUpdate.
if (state == ForecastState.PREDICTING)
{
// PREDICTING checks state, which happens in update()
}
else if (state == ForecastState.BLENDING)
{
// TODO snapshot interpolation
@ -319,24 +345,13 @@ void UpdateClient()
}
else if (state == ForecastState.FOLLOWING)
{
// hard set position & rotation.
// TODO snapshot interpolation
tf.SetPositionAndRotation(lastReceivedState.position, lastReceivedState.rotation);
// FOLLOWING sets Transform, which happens in Update().
}
}
void Update()
{
if (isServer) UpdateServer();
if (isClientOnly) UpdateClient();
}
void FixedUpdate()
{
// on clients (not host) we record the current state every FixedUpdate.
// this is cheap, and allows us to keep a dense history.
if (!isClientOnly) return;
if (isClientOnly) FixedUpdateClient();
}
void OnDrawGizmos()