Misc replay related changes (#17102)

This commit is contained in:
Leon Friedrich
2023-06-05 16:33:49 +12:00
committed by GitHub
parent 7d178555e1
commit a8eee5878a
14 changed files with 132 additions and 75 deletions

View File

@@ -133,35 +133,7 @@ namespace Content.Shared.Movement.Systems
}
}
var angleDiff = Angle.ShortestDistance(mover.RelativeRotation, mover.TargetRelativeRotation);
// if we've just traversed then lerp to our target rotation.
if (!angleDiff.EqualsApprox(Angle.Zero, 0.001))
{
var adjustment = angleDiff * 5f * frameTime;
var minAdjustment = 0.01 * frameTime;
if (angleDiff < 0)
{
adjustment = Math.Min(adjustment, -minAdjustment);
adjustment = Math.Clamp(adjustment, angleDiff, -angleDiff);
}
else
{
adjustment = Math.Max(adjustment, minAdjustment);
adjustment = Math.Clamp(adjustment, -angleDiff, angleDiff);
}
mover.RelativeRotation += adjustment;
mover.RelativeRotation.FlipPositive();
Dirty(mover);
}
else if (!angleDiff.Equals(Angle.Zero))
{
mover.TargetRelativeRotation.FlipPositive();
mover.RelativeRotation = mover.TargetRelativeRotation;
Dirty(mover);
}
LerpRotation(mover, frameTime);
if (!canMove
|| physicsComponent.BodyStatus != BodyStatus.OnGround
@@ -282,6 +254,39 @@ namespace Content.Shared.Movement.Systems
PhysicsSystem.SetAngularVelocity(physicsUid, 0, body: physicsComponent);
}
public void LerpRotation(InputMoverComponent mover, float frameTime)
{
var angleDiff = Angle.ShortestDistance(mover.RelativeRotation, mover.TargetRelativeRotation);
// if we've just traversed then lerp to our target rotation.
if (!angleDiff.EqualsApprox(Angle.Zero, 0.001))
{
var adjustment = angleDiff * 5f * frameTime;
var minAdjustment = 0.01 * frameTime;
if (angleDiff < 0)
{
adjustment = Math.Min(adjustment, -minAdjustment);
adjustment = Math.Clamp(adjustment, angleDiff, -angleDiff);
}
else
{
adjustment = Math.Max(adjustment, minAdjustment);
adjustment = Math.Clamp(adjustment, -angleDiff, angleDiff);
}
mover.RelativeRotation += adjustment;
mover.RelativeRotation.FlipPositive();
Dirty(mover);
}
else if (!angleDiff.Equals(Angle.Zero))
{
mover.TargetRelativeRotation.FlipPositive();
mover.RelativeRotation = mover.TargetRelativeRotation;
Dirty(mover);
}
}
private void Friction(float minimumFrictionSpeed, float frameTime, float friction, ref Vector2 velocity)
{
var speed = velocity.Length;