Fix aircraft jittering

This commit is contained in:
Gustas
2023-05-03 10:39:45 +03:00
committed by Matthias Mailänder
parent 32b0003a72
commit d686634c0b
2 changed files with 17 additions and 3 deletions

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -175,7 +176,19 @@ namespace OpenRA.Mods.Common.Activities
return true;
var isSlider = aircraft.Info.CanSlide;
var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : aircraft.Facing;
var desiredFacing = aircraft.Facing;
if (delta.HorizontalLengthSquared != 0)
{
var facing = delta.Yaw;
// Prevent jittering.
var diff = Math.Abs(facing.Angle - desiredFacing.Angle);
var deadzone = aircraft.Info.TurnDeadzone.Angle;
if (diff > deadzone && diff < 1024 - deadzone)
desiredFacing = facing;
}
var move = isSlider ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
// Inside the minimum range, so reverse if we CanSlide, otherwise face away from the target.
@@ -184,9 +197,7 @@ namespace OpenRA.Mods.Common.Activities
if (isSlider)
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move);
else
{
FlyTick(self, aircraft, desiredFacing + new WAngle(512), aircraft.Info.CruiseAltitude, move);
}
return false;
}

View File

@@ -56,6 +56,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Turn speed to apply when aircraft flies in circles while idle. Defaults to TurnSpeed if undefined.")]
public readonly WAngle? IdleTurnSpeed = null;
[Desc("When flying if the difference between current facing and desired facing is less than this value, don't turn. This prevents visual jitter.")]
public readonly WAngle TurnDeadzone = new(2);
[Desc("Maximum flight speed when cruising.")]
public readonly int Speed = 1;