add logic for waiting before switching to aim states

This commit is contained in:
in0finite 2021-12-18 16:00:02 +01:00
parent fda6997579
commit bef07417b3
3 changed files with 17 additions and 2 deletions

View file

@ -70,12 +70,25 @@ namespace SanAndreasUnity.Behaviours.Peds.States
protected virtual void SwitchToAimState()
{
if (m_ped.IsAimOn && m_ped.IsHoldingWeapon)
if (m_ped.IsAimOn && m_ped.IsHoldingWeapon && EnoughTimePassedToSwitchToAimState(m_ped))
{
BaseAimMovementState.SwitchToAimMovementStateBasedOnInput (m_ped);
}
}
public static bool EnoughTimePassedToSwitchToAimState(Ped ped)
{
var aimStates = ped.CachedAimStates;
for (int i = 0; i < aimStates.Count; i++)
{
if (Time.time - aimStates[i].LastTimeWhenDeactivated < PedManager.Instance.minTimeToReturnToAimState)
return false;
}
return true;
}
protected override void UpdateAnims ()
{
if (m_ped.CurrentWeapon != null)

View file

@ -29,7 +29,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
public static void SwitchToAimState(Ped ped)
{
// can only switch to CrouchAim state
if( ped.IsAimOn && ped.IsHoldingWeapon )
if( ped.IsAimOn && ped.IsHoldingWeapon && BaseMovementState.EnoughTimePassedToSwitchToAimState(ped) )
{
ped.SwitchState<CrouchAimState>();
}

View file

@ -20,6 +20,8 @@ namespace SanAndreasUnity.Behaviours
public FocusPointParameters playerPedFocusPointParameters = new FocusPointParameters(false, 0f, 3f);
public FocusPointParameters npcPedFocusPointParameters = FocusPointParameters.Default;
public float minTimeToReturnToAimState = 0.33f;
[Header("Camera")]
public float cameraDistanceFromPed = 3f;