smooth out switching between aim movement states

This commit is contained in:
in0finite 2021-12-26 23:16:14 +01:00
parent 6037568f0a
commit abac2b54f5
3 changed files with 31 additions and 3 deletions

View file

@ -23,9 +23,13 @@ namespace SanAndreasUnity.Behaviours.Peds.States
protected bool m_wasAimingBackWithAWAWeapon = false;
protected float m_timeSinceAimingBackWithAWAWeapon = 0f;
public virtual float TimeUntilStateCanBeSwitchedToOtherAimMovementState => PedManager.Instance.timeUntilAimMovementStateCanBeSwitchedToOtherAimMovementState;
public virtual float TimeUntilStateCanBeEnteredFromOtherAimMovementState => PedManager.Instance.timeUntilAimMovementStateCanBeEnteredFromOtherAimMovementState;
public override void OnBecameActive()
public override void OnBecameActive()
{
base.OnBecameActive();
@ -108,10 +112,30 @@ namespace SanAndreasUnity.Behaviours.Peds.States
protected virtual bool SwitchToOtherAimMovementState ()
{
BaseAimMovementState.SwitchToAimMovementStateBasedOnInput (m_ped);
System.Type type = GetAimMovementStateToSwitchToBasedOnInput(m_ped);
var state = (BaseAimMovementState)m_ped.GetStateOrLogError(type);
if (!EnoughTimePassedToSwitchBetweenAimMovementStates(this, state))
return false;
m_ped.SwitchState(type);
return ! this.IsActiveState;
}
public static bool EnoughTimePassedToSwitchBetweenAimMovementStates(
BaseAimMovementState currentState,
BaseAimMovementState targetState)
{
if (currentState.TimeSinceActivated < currentState.TimeUntilStateCanBeSwitchedToOtherAimMovementState)
return false;
if (targetState.TimeSinceDeactivated < targetState.TimeUntilStateCanBeEnteredFromOtherAimMovementState)
return false;
return true;
}
protected virtual bool SwitchToFallingState ()
{
return false;

View file

@ -9,8 +9,10 @@ namespace SanAndreasUnity.Behaviours.Peds.States
{
public override AnimId aimWithArm_LowerAnim { get { return m_ped.CurrentWeapon.IdleAnim; } }
public override float TimeUntilStateCanBeSwitchedToOtherAimMovementState => 0f;
public override void OnBecameActive ()
public override void OnBecameActive ()
{
base.OnBecameActive ();
// m_ped.PlayerModel.PlayAnim (AnimGroup.MyWalkCycle, AnimIndex.GUN_STAND);

View file

@ -24,6 +24,8 @@ namespace SanAndreasUnity.Behaviours
public float minTimeToReturnToNonAimStateFromAimState = 0.33f;
public float timeUntilMovementStateCanBeSwitchedToOtherMovementState = 0.166f;
public float timeUntilMovementStateCanBeEnteredFromOtherMovementState = 0.166f;
public float timeUntilAimMovementStateCanBeSwitchedToOtherAimMovementState = 0.166f;
public float timeUntilAimMovementStateCanBeEnteredFromOtherAimMovementState = 0.166f;
[Header("Camera")]