smooth out switching from aim to non-aim states

This commit is contained in:
in0finite 2021-12-18 17:16:40 +01:00
parent d62eb43c78
commit 0214244ee3
4 changed files with 16 additions and 2 deletions

View file

@ -167,6 +167,7 @@ MonoBehaviour:
revealRadius: 150
timeToKeepRevealingAfterRemoved: 3
minTimeToReturnToAimState: 0.33
minTimeToReturnToNonAimStateFromAimState: 0.33
cameraDistanceFromPed: 5
minCameraDistanceFromPed: 2
maxCameraDistanceFromPed: 30

View file

@ -61,7 +61,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States
{
// check if we should exit aiming state
if (!m_ped.IsHoldingWeapon || !m_ped.IsAimOn)
if (null == m_weapon)
{
BaseMovementState.SwitchToMovementStateBasedOnInput(m_ped);
return true;
}
// wait until we start pointing gun - this is used to prevent fast state switching
if (this.TimeSinceActivated < Mathf.Max(this.AimAnimMaxTime, PedManager.Instance.minTimeToReturnToNonAimStateFromAimState))
return false;
if (!m_ped.IsAimOn)
{
BaseMovementState.SwitchToMovementStateBasedOnInput (m_ped);
return true;
@ -69,7 +80,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
if (m_ped.IsSprintOn)
{
if (null == m_weapon || m_weapon.CanSprintWithIt)
if (m_weapon.CanSprintWithIt)
{
m_ped.SwitchState<SprintState>();
return true;

View file

@ -23,6 +23,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
protected bool m_shouldSendButtonEvents { get { return !m_isServer && m_ped.IsControlledByLocalPlayer; } }
public float LastTimeWhenActivated { get; set; } = 0f;
public float TimeSinceActivated => Time.time - this.LastTimeWhenActivated;
public float LastTimeWhenDeactivated { get; set; } = 0f;
public float TimeSinceDeactivated => Time.time - this.LastTimeWhenDeactivated;

View file

@ -21,6 +21,7 @@ namespace SanAndreasUnity.Behaviours
public FocusPointParameters npcPedFocusPointParameters = FocusPointParameters.Default;
public float minTimeToReturnToAimState = 0.33f;
public float minTimeToReturnToNonAimStateFromAimState = 0.33f;
[Header("Camera")]