diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs index 6fa52591..4d09df5c 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseMovementState.cs @@ -13,6 +13,9 @@ namespace SanAndreasUnity.Behaviours.Peds.States public abstract AnimId movementAnim { get; } public abstract AnimId movementWeaponAnim { get; } + public virtual float TimeUntilStateCanBeSwitchedToOtherMovementState => PedManager.Instance.timeUntilMovementStateCanBeSwitchedToOtherMovementState; + public virtual float TimeUntilStateCanBeEnteredFromOtherMovementState => PedManager.Instance.timeUntilMovementStateCanBeEnteredFromOtherMovementState; + public override void UpdateState() { @@ -36,7 +39,15 @@ namespace SanAndreasUnity.Behaviours.Peds.States protected virtual void SwitchToMovementState() { - BaseMovementState.SwitchToMovementStateBasedOnInput (m_ped); + if (this.TimeSinceActivated <= this.TimeUntilStateCanBeSwitchedToOtherMovementState) + return; + + System.Type type = BaseMovementState.GetMovementStateToSwitchToBasedOnInput(m_ped); + var state = (BaseMovementState) m_ped.GetStateOrLogError(type); + if (state.TimeSinceDeactivated <= state.TimeUntilStateCanBeEnteredFromOtherMovementState) + return; + + m_ped.SwitchState(type); } public static void SwitchToMovementStateBasedOnInput (Ped ped) diff --git a/Assets/Scripts/Behaviours/Ped/States/StandState.cs b/Assets/Scripts/Behaviours/Ped/States/StandState.cs index ff1f5258..56fbc292 100644 --- a/Assets/Scripts/Behaviours/Ped/States/StandState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/StandState.cs @@ -10,8 +10,10 @@ namespace SanAndreasUnity.Behaviours.Peds.States public override AnimId movementAnim { get { return new AnimId (AnimGroup.WalkCycle, AnimIndex.Idle); } } public override AnimId movementWeaponAnim { get { return m_ped.CurrentWeapon.IdleAnim; } } + public override float TimeUntilStateCanBeSwitchedToOtherMovementState => 0f; - public override void UpdateState() { + + public override void UpdateState() { base.UpdateState(); diff --git a/Assets/Scripts/Behaviours/PedManager.cs b/Assets/Scripts/Behaviours/PedManager.cs index bc30358f..ad26adaf 100644 --- a/Assets/Scripts/Behaviours/PedManager.cs +++ b/Assets/Scripts/Behaviours/PedManager.cs @@ -22,6 +22,8 @@ namespace SanAndreasUnity.Behaviours public float minTimeToReturnToAimState = 0.33f; public float minTimeToReturnToNonAimStateFromAimState = 0.33f; + public float timeUntilMovementStateCanBeSwitchedToOtherMovementState = 0.166f; + public float timeUntilMovementStateCanBeEnteredFromOtherMovementState = 0.166f; [Header("Camera")]