Fix eye lerping stuttering (#11428)
This commit is contained in:
@@ -87,7 +87,7 @@ public sealed class EyeLerpingSystem : EntitySystem
|
|||||||
foundEyes.Add(entity);
|
foundEyes.Add(entity);
|
||||||
moverQuery.TryGetComponent(entity, out var mover);
|
moverQuery.TryGetComponent(entity, out var mover);
|
||||||
xformQuery.TryGetComponent(entity, out var xform);
|
xformQuery.TryGetComponent(entity, out var xform);
|
||||||
lerpInfo.LastRotation = eye.Rotation;
|
lerpInfo.LastRotation = lerpInfo.TargetRotation;
|
||||||
lerpInfo.TargetRotation = GetRotation(xformQuery, mover, xform);
|
lerpInfo.TargetRotation = GetRotation(xformQuery, mover, xform);
|
||||||
|
|
||||||
if (xform != null)
|
if (xform != null)
|
||||||
@@ -109,6 +109,20 @@ public sealed class EyeLerpingSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does the eye need to lerp or is its rotation matched.
|
||||||
|
/// </summary>
|
||||||
|
private bool NeedsLerp(EntityUid uid, InputMoverComponent? mover = null)
|
||||||
|
{
|
||||||
|
if (mover == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (mover.RelativeRotation.Equals(mover.TargetRelativeRotation))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private Angle GetRotation(EntityQuery<TransformComponent> xformQuery, InputMoverComponent? mover = null, TransformComponent? xform = null)
|
private Angle GetRotation(EntityQuery<TransformComponent> xformQuery, InputMoverComponent? mover = null, TransformComponent? xform = null)
|
||||||
{
|
{
|
||||||
// If we can move then tie our eye to our inputs (these also get lerped so it should be fine).
|
// If we can move then tie our eye to our inputs (these also get lerped so it should be fine).
|
||||||
@@ -160,12 +174,19 @@ public sealed class EyeLerpingSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var tickFraction = (float) _gameTiming.TickFraction / ushort.MaxValue;
|
var tickFraction = (float) _gameTiming.TickFraction / ushort.MaxValue;
|
||||||
const double lerpMinimum = 0.00001;
|
const double lerpMinimum = 0.00001;
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
foreach (var (eye, entity) in GetEyes())
|
foreach (var (eye, entity) in GetEyes())
|
||||||
{
|
{
|
||||||
if (!_activeEyes.TryGetValue(entity, out var lerpInfo))
|
if (!_activeEyes.TryGetValue(entity, out var lerpInfo))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (TryComp<InputMoverComponent>(entity, out var mover) && !NeedsLerp(entity, mover))
|
||||||
|
{
|
||||||
|
eye.Rotation = GetRotation(xformQuery, mover);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var shortest = Angle.ShortestDistance(lerpInfo.LastRotation, lerpInfo.TargetRotation);
|
var shortest = Angle.ShortestDistance(lerpInfo.LastRotation, lerpInfo.TargetRotation);
|
||||||
|
|
||||||
if (Math.Abs(shortest.Theta) < lerpMinimum)
|
if (Math.Abs(shortest.Theta) < lerpMinimum)
|
||||||
|
|||||||
Reference in New Issue
Block a user