< Summary

Information
Class: Trailblazer.Navigation.Motor.MoveLocomotion
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/MoveLocomotion.cs
Line coverage
100%
Covered lines: 55
Uncovered lines: 0
Coverable lines: 55
Total lines: 216
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%11100%
get_IsEnabled()100%11100%
set_IsEnabled(...)100%22100%
RecordData(...)100%44100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/MoveLocomotion.cs

#LineLine coverage
 1using Chronicler;
 2using FixedMathSharp;
 3using Trailblazer.Support;
 4
 5namespace Trailblazer.Navigation.Motor;
 6
 7/// <summary>
 8/// Handles the scout's movement, including speed limits, acceleration, and velocity calculations.
 9/// </summary>
 10/// <remarks>
 11/// This locomotion module governs how the scout accelerates, decelerates, and interacts with terrain slopes.
 12/// It tracks position changes and velocity updates for consistent movement behavior.
 13/// </remarks>
 14public class MoveLocomotion : ILocomotion
 15{
 16    #region Constants
 17
 18    /// <summary>
 19    /// The minimum velocity threshold below which movement is considered negligible.
 20    /// </summary>
 121    public static readonly Fixed64 VelocityEpsilon = Fixed64.FromRaw(0x418938L); //0.001f;
 22
 23    /// <summary>
 24    /// Default maximum walking speed.
 25    /// </summary>
 126    public static readonly Fixed64 DefaultMaxSlowSpeed = (Fixed64)0.1f;//1d;
 27
 28    /// <summary>
 29    /// Default maximum jogging speed.
 30    /// </summary>
 131    public static readonly Fixed64 DefaultMaxModerateSpeed = (Fixed64)0.25d;//2d;
 32
 33    /// <summary>
 34    /// Default maximum sprinting speed.
 35    /// </summary>
 136    public static readonly Fixed64 DefaultMaxFastSpeed = (Fixed64)0.5d;//3d;
 37
 38    /// <summary>
 39    /// Default maximum sideways movement speed.
 40    /// </summary>
 141    public static readonly Fixed64 DefaultMaxSidewaysSpeed = (Fixed64)0.15d;//2d;
 42
 43    /// <summary>
 44    /// Default maximum backward movement speed.
 45    /// </summary>
 146    public static readonly Fixed64 DefaultMaxBackwardsSpeed = (Fixed64)0.15d;//2d;
 47
 48    /// <summary>
 49    /// Default maximum acceleration when moving on the ground.
 50    /// </summary>
 51    /// <remarks>
 52    /// This is timescaled, with a default TimeDelta of `0.03125` this resolves to 1.
 53    /// </remarks>
 154    public static readonly Fixed64 DefaultMaxGroundAcceleration = (Fixed64)32;
 55
 56    /// <summary>
 57    /// Default maximum acceleration when moving in the air.
 58    /// </summary>
 59    /// <remarks>
 60    /// This is timescaled, with a default TimeDelta of `0.03125` this resolves to `0.625`.
 61    /// </remarks>
 162    public static readonly Fixed64 DefaultMaxAirAcceleration = (Fixed64)20;
 63
 64    /// <summary>
 65    /// Default slope speed modifier curve, determining speed adjustments based on incline.
 66    /// </summary>
 67    /// <remarks>
 68    /// - Full downward slope (-90°) retains full speed.
 69    /// - Flat ground (0°) retains full speed.
 70    /// - Full upward slope (90°) reduces speed to zero.
 71    /// </remarks>
 172    public static readonly FixedCurve DefaultSlopeSpeedModifier = new(FixedCurveMode.Linear,
 173            new FixedCurveKey(-90, 1.5),  // Full downward slope boosts speed 1.5x
 174            new FixedCurveKey(-45, 1.2),  // Moderate downward slope boosts speed 1.2x
 175            new FixedCurveKey(0, 1),      // Flat ground, normal speed
 176            new FixedCurveKey(45, 0.8),   // Moderate uphill slows down
 177            new FixedCurveKey(90, 0)      // Full uphill completely stops movement
 178        );
 79
 80    /// <summary>
 81    /// The default maximum slope angle before a surface is considered too steep for normal control.
 82    /// </summary>
 183    public static readonly Fixed64 DefaultSlopeLimit = Fixed64.FromRaw(0x2D00000000L); // 45f;
 84
 85    /// <summary>
 86    /// The default passive drag factor applied while moving through water.
 87    /// </summary>
 188    public static readonly Fixed64 DefaultWaterDragFactor = Fixed64.FromRaw(0x10000000L); // ~0.0625
 89
 90    #endregion
 91
 92    #region Configuration State
 93
 94    /// <summary>
 95    /// Determines whether movement mechanics are enabled.
 96    /// </summary>
 82497    private bool _isEnabled = true;
 98
 99    /// <summary>
 100    /// The maximum speed when walking.
 101    /// </summary>
 824102    public Fixed64 MaxSlowSpeed = DefaultMaxSlowSpeed;
 103
 104    /// <summary>
 105    /// The maximum speed when jogging.
 106    /// </summary>
 824107    public Fixed64 MaxModerateSpeed = DefaultMaxModerateSpeed;
 108
 109    /// <summary>
 110    /// The maximum speed when sprinting.
 111    /// </summary>
 824112    public Fixed64 MaxFastSpeed = DefaultMaxFastSpeed;
 113
 114    /// <summary>
 115    /// The maximum speed when moving sideways.
 116    /// </summary>
 824117    public Fixed64 MaxSidewaysSpeed = DefaultMaxSidewaysSpeed;
 118
 119    /// <summary>
 120    /// The maximum speed when moving backward.
 121    /// </summary>
 824122    public Fixed64 MaxBackwardsSpeed = DefaultMaxBackwardsSpeed;
 123
 124    /// <summary>
 125    /// The maximum acceleration when moving on the ground.
 126    /// Higher values result in quicker acceleration.
 127    /// </summary>
 824128    public Fixed64 MaxGroundAcceleration = DefaultMaxGroundAcceleration;
 129
 130    /// <summary>
 131    /// The maximum acceleration when moving in the air.
 132    /// </summary>
 824133    public Fixed64 MaxAirAcceleration = DefaultMaxAirAcceleration;
 134
 135    /// <summary>
 136    /// A global multiplier applied to movement speed.
 137    /// </summary>
 824138    public Fixed64 MoveSpeedMultiplier = Fixed64.One;
 139
 140    /// <summary>
 141    /// Determines whether movement speed is adjusted based on the slope of the terrain.
 142    /// </summary>
 824143    public bool ModifySpeedOnSlope = true;
 144
 145    /// <summary>
 146    /// A curve controlling how speed is affected by terrain slope.
 147    /// </summary>
 824148    public FixedCurve SlopeSpeedMultiplier = DefaultSlopeSpeedModifier;
 149
 150    /// <summary>
 151    /// The slope angle threshold at which a surface becomes too steep for normal movement control.
 152    /// </summary>
 824153    public Fixed64 SlopeLimit = DefaultSlopeLimit;
 154
 155    /// <summary>
 156    /// Passive drag applied whenever the motor is in water, even if the water locomotion is absent or inactive.
 157    /// </summary>
 824158    public Fixed64 WaterDragFactor = DefaultWaterDragFactor;
 159
 160    #endregion
 161
 162    #region Transient State
 163
 164    /// <inheritdoc cref="ILocomotion.IsEnabled"/>
 165    public bool IsEnabled
 166    {
 20167        get => _isEnabled;
 168        set
 169        {
 2170            _isEnabled = value;
 2171            if (!_isEnabled)
 1172                this.ClearTransientState();
 2173        }
 174    }
 175
 176    /// <summary>
 177    /// The scout’s current velocity in world space.
 178    /// </summary>
 179    [Transient]
 180    public Vector3d FrameVelocity { get; set; }
 181
 182    #endregion
 183
 184    #region Serialization
 185
 186    /// <inheritdoc />
 187    public void RecordData(IChronicler chronicler)
 188    {
 106189        RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true);
 106190        RecordValues.Look(chronicler, ref MaxSlowSpeed, "MaxSlowSpeed", DefaultMaxSlowSpeed);
 106191        RecordValues.Look(chronicler, ref MaxModerateSpeed, "MaxModerateSpeed", DefaultMaxModerateSpeed);
 106192        RecordValues.Look(chronicler, ref MaxFastSpeed, "MaxFastSpeed", DefaultMaxFastSpeed);
 106193        RecordValues.Look(chronicler, ref MaxSidewaysSpeed, "MaxSidewaysSpeed", DefaultMaxSidewaysSpeed);
 106194        RecordValues.Look(chronicler, ref MaxBackwardsSpeed, "MaxBackwardsSpeed", DefaultMaxBackwardsSpeed);
 106195        RecordValues.Look(chronicler, ref MaxGroundAcceleration, "MaxGroundAcceleration", DefaultMaxGroundAcceleration);
 106196        RecordValues.Look(chronicler, ref MaxAirAcceleration, "MaxAirAcceleration", DefaultMaxAirAcceleration);
 106197        RecordValues.Look(chronicler, ref MoveSpeedMultiplier, "MoveSpeedMultiplier", Fixed64.One);
 106198        RecordValues.Look(chronicler, ref ModifySpeedOnSlope, "ModifySpeedOnSlope", true);
 106199        RecordValues.Look(chronicler, ref SlopeSpeedMultiplier, "SlopeSpeedMultiplier", DefaultSlopeSpeedModifier);
 106200        RecordValues.Look(chronicler, ref SlopeLimit, "SlopeLimit", DefaultSlopeLimit);
 106201        RecordValues.Look(chronicler, ref WaterDragFactor, "WaterDragFactor", DefaultWaterDragFactor);
 202
 106203        Vector3d frameVelocity = FrameVelocity;
 106204        RecordValues.Look(chronicler, ref frameVelocity, "FrameVelocity", Vector3d.Zero);
 205
 106206        if (chronicler.Mode == SerializationMode.Loading)
 207        {
 53208            FrameVelocity = frameVelocity;
 209
 53210            if (!_isEnabled)
 2211                this.ClearTransientState();
 212        }
 106213    }
 214
 215    #endregion
 216}