| | | 1 | | //======================================================================= |
| | | 2 | | // SlideLocomotion.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using Chronicler; |
| | | 9 | | using FixedMathSharp; |
| | | 10 | | using Trailblazer.Support; |
| | | 11 | | |
| | | 12 | | namespace Trailblazer.Navigation.Motor; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Handles the scout's sliding behavior when traversing steep surfaces. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <remarks> |
| | | 18 | | /// This locomotion module determines when the scout should slide based on terrain steepness |
| | | 19 | | /// and controls how much influence the scout has over the slide direction and speed. |
| | | 20 | | /// </remarks> |
| | | 21 | | public class SlideLocomotion : ILocomotion |
| | | 22 | | { |
| | | 23 | | #region Constants |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// The default speed at which the scout slides down steep surfaces. |
| | | 27 | | /// </summary> |
| | 1 | 28 | | public static readonly Fixed64 DefaultSlidingSpeed = (Fixed64)30; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// The default amount of control the scout has while sliding sideways. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <remarks> |
| | | 34 | | /// A value of 0.5 allows the scout to slide sideways at half the speed of downward sliding. |
| | | 35 | | /// </remarks> |
| | 1 | 36 | | public static readonly Fixed64 DefaultSidewaysControl = (Fixed64)1; |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// The default amount the scout can influence sliding speed. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <remarks> |
| | | 42 | | /// A value of 0.5 allows the scout to increase sliding speed up to 150% or reduce it to 50%. |
| | | 43 | | /// </remarks> |
| | 1 | 44 | | public static readonly Fixed64 DefaultSpeedControl = Fixed64.Half; |
| | | 45 | | |
| | | 46 | | #endregion |
| | | 47 | | |
| | | 48 | | #region Configuration State |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Determines whether sliding mechanics are enabled. |
| | | 52 | | /// </summary> |
| | 1149 | 53 | | private bool _isEnabled = true; |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// The speed at which the scout slides when on a steep surface. |
| | | 57 | | /// </summary> |
| | 1149 | 58 | | public Fixed64 SlidingSpeed = DefaultSlidingSpeed; |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Determines how much control the scout has while sliding sideways. |
| | | 62 | | /// </summary> |
| | | 63 | | /// <remarks> |
| | | 64 | | /// A higher value increases lateral movement freedom during a slide. |
| | | 65 | | /// </remarks> |
| | 1149 | 66 | | public Fixed64 SidewaysControl = DefaultSidewaysControl; |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Determines how much the scout can influence sliding speed. |
| | | 70 | | /// </summary> |
| | 1149 | 71 | | public Fixed64 SpeedControl = DefaultSpeedControl; |
| | | 72 | | |
| | | 73 | | #endregion |
| | | 74 | | |
| | | 75 | | #region Transient State |
| | | 76 | | |
| | | 77 | | /// <inheritdoc cref="ILocomotion.IsEnabled"/> |
| | | 78 | | public bool IsEnabled |
| | | 79 | | { |
| | 274 | 80 | | get => _isEnabled; |
| | | 81 | | set |
| | | 82 | | { |
| | 2 | 83 | | _isEnabled = value; |
| | 2 | 84 | | if (!_isEnabled) |
| | 1 | 85 | | this.ClearTransientState(); |
| | 2 | 86 | | } |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Indicates whether the scout is currently sliding. |
| | | 91 | | /// </summary> |
| | | 92 | | [Transient] |
| | | 93 | | public bool IsSliding { get; set; } |
| | | 94 | | |
| | | 95 | | #endregion |
| | | 96 | | |
| | | 97 | | /// <inheritdoc /> |
| | | 98 | | public void RecordData(IChronicler chronicler) |
| | | 99 | | { |
| | 158 | 100 | | RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true); |
| | 158 | 101 | | RecordValues.Look(chronicler, ref SlidingSpeed, "SlidingSpeed", DefaultSlidingSpeed); |
| | 158 | 102 | | RecordValues.Look(chronicler, ref SidewaysControl, "SidewaysControl", DefaultSidewaysControl); |
| | 158 | 103 | | RecordValues.Look(chronicler, ref SpeedControl, "SpeedControl", DefaultSpeedControl); |
| | | 104 | | |
| | 158 | 105 | | bool isSliding = IsSliding; |
| | 158 | 106 | | RecordValues.Look(chronicler, ref isSliding, "IsSliding", false); |
| | | 107 | | |
| | 158 | 108 | | if (chronicler.Mode == SerializationMode.Loading) |
| | | 109 | | { |
| | 74 | 110 | | IsSliding = isSliding; |
| | | 111 | | |
| | 74 | 112 | | if (!_isEnabled) |
| | 2 | 113 | | this.ClearTransientState(); |
| | | 114 | | } |
| | 158 | 115 | | } |
| | | 116 | | } |