smooth out switching between movement states

This commit is contained in:
in0finite 2021-12-19 02:01:13 +01:00
parent 75619c21a1
commit d9acfbb431
3 changed files with 17 additions and 2 deletions

View file

@ -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)

View file

@ -10,6 +10,8 @@ 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() {

View file

@ -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")]