smooth out switching between crouch states and stand state

This commit is contained in:
in0finite 2021-12-19 22:13:34 +01:00
parent b9a57dd79e
commit f8e8f4aeb8
3 changed files with 16 additions and 4 deletions

View file

@ -140,7 +140,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States
public override void OnCrouchButtonPressed ()
{
if (m_isServer)
m_ped.SwitchState<CrouchState>();
{
var crouchState = m_ped.GetState<CrouchState>();
if (BaseMovementState.EnoughTimePassedToSwitchBetweenMovementStates(this, crouchState))
m_ped.SwitchState(crouchState.GetType());
}
else
base.OnCrouchButtonPressed();
}

View file

@ -38,7 +38,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States
public override void OnCrouchButtonPressed ()
{
if (m_isServer)
m_ped.SwitchState<StandState>();
{
var standState = m_ped.GetState<StandState>();
if (BaseMovementState.EnoughTimePassedToSwitchBetweenMovementStates(this, standState))
m_ped.SwitchState(standState.GetType());
}
else
base.OnCrouchButtonPressed();
}

View file

@ -85,8 +85,12 @@ namespace SanAndreasUnity.Behaviours.Peds.States
// switch to stand state
if (m_isServer)
m_ped.SwitchState<StandState>();
else
{
var standState = m_ped.GetState<StandState>();
if (BaseMovementState.EnoughTimePassedToSwitchBetweenMovementStates(this, standState))
m_ped.SwitchState(standState.GetType());
}
else
base.OnCrouchButtonPressed();
}