Smoother sync, I guess

This commit is contained in:
Sardelka9515
2023-03-19 17:47:00 +08:00
parent 0bc89a9bf3
commit bda1dac90b
2 changed files with 11 additions and 5 deletions

View File

@ -57,6 +57,7 @@ namespace RageCoop.Client
internal bool IsSubmarineCar;
internal bool IsDeluxo;
internal bool IsTrain;
[DebugTunable]
static float RotCalMult = 10f;

View File

@ -22,7 +22,7 @@ namespace RageCoop.Client
return;
DisplayVehicle(NeedUpdate);
DisplayVehicle();
// Skip update if no new sync message has arrived.
if (!NeedUpdate) return;
@ -158,7 +158,7 @@ namespace RageCoop.Client
LastUpdated = Ticked;
}
private void DisplayVehicle(bool updated)
private void DisplayVehicle()
{
_predictedPosition = Predict(Position);
var current = MainVehicle.ReadPosition();
@ -173,6 +173,8 @@ namespace RageCoop.Client
return;
}
var stopped = Velocity == Vector3.Zero;
// Calibrate position
if (distSquared > 0.03 * 0.03)
{
@ -180,9 +182,12 @@ namespace RageCoop.Client
else MainVehicle.ApplyWorldForceCenterOfMass(cali, ForceType.InternalImpulse, true);
}
// Calibrate rotation
var diff = Quaternion.Diff(MainVehicle.ReadQuaternion());
MainVehicle.WorldRotationVelocity = diff.ToEulerAngles() * RotCalMult;
if (NeedUpdate || stopped)
{
// Calibrate rotation
var diff = Quaternion.Diff(MainVehicle.ReadQuaternion());
MainVehicle.WorldRotationVelocity = diff.ToEulerAngles() * RotCalMult;
}
}
private bool CreateVehicle()