diff --git a/Assets/Prefabs/GameManager.prefab b/Assets/Prefabs/GameManager.prefab index 61d1b269..a76cba57 100644 --- a/Assets/Prefabs/GameManager.prefab +++ b/Assets/Prefabs/GameManager.prefab @@ -131,6 +131,7 @@ MonoBehaviour: AIMWITHARM_upperArmEndRotationEulers: {x: 170, y: -90, z: -2.412} AIMWITHARM_maxAimAngle: 95 AIMWITHARM_maxHeadRotationAngle: 50 + AIMWITHARM_timeUntilAbleToStopAimingBack: 0.33 crouchSpineRotationOffset: {x: 0, y: 35, z: 90} crouchSpineRotationOffset2: {x: 0, y: 15, z: 90} projectileRaycastMask: @@ -167,7 +168,11 @@ MonoBehaviour: revealRadius: 150 timeToKeepRevealingAfterRemoved: 3 minTimeToReturnToAimState: 0.33 - minTimeToReturnToNonAimStateFromAimState: 0.15 + minTimeToReturnToNonAimStateFromAimState: 0.25 + timeUntilMovementStateCanBeSwitchedToOtherMovementState: 0.166 + timeUntilMovementStateCanBeEnteredFromOtherMovementState: 0.166 + timeUntilAimMovementStateCanBeSwitchedToOtherAimMovementState: 0.166 + timeUntilAimMovementStateCanBeEnteredFromOtherAimMovementState: 0.166 cameraDistanceFromPed: 5 minCameraDistanceFromPed: 2 maxCameraDistanceFromPed: 30 diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index ff109835..7c888c83 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -156,7 +156,7 @@ namespace SanAndreasUnity.Behaviours .Cast() .ToArray(); this.CachedNonAimStates = _stateContainer.States - .Where(_ => _ is not Peds.States.IAimState) + .Where(_ => !(_ is Peds.States.IAimState)) .ToArray(); this.AwakeForDamage (); diff --git a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs index 9ac36474..0abce9e7 100644 --- a/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/BaseAimMovementState.cs @@ -83,10 +83,10 @@ namespace SanAndreasUnity.Behaviours.Peds.States 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)) + // prevent fast state switching + if (!EnoughTimePassedToSwitchToNonAimState(m_ped, Mathf.Max(this.AimAnimMaxTime, PedManager.Instance.minTimeToReturnToNonAimStateFromAimState))) return false; - + if (!m_ped.IsAimOn) { BaseMovementState.SwitchToMovementStateBasedOnInput (m_ped); @@ -105,6 +105,19 @@ namespace SanAndreasUnity.Behaviours.Peds.States return false; } + public static bool EnoughTimePassedToSwitchToNonAimState(Ped ped, float timeRequiredToPass) + { + var states = ped.CachedNonAimStates; + + for (int i = 0; i < states.Count; i++) + { + if (states[i].TimeSinceDeactivated < timeRequiredToPass) + return false; + } + + return true; + } + protected virtual bool SwitchToFiringState () { return false; diff --git a/Assets/Scripts/Behaviours/Ped/States/CrouchAimState.cs b/Assets/Scripts/Behaviours/Ped/States/CrouchAimState.cs index fbbf9852..1fc09882 100644 --- a/Assets/Scripts/Behaviours/Ped/States/CrouchAimState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/CrouchAimState.cs @@ -26,8 +26,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States 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)) + // prevent fast state switching + if (!EnoughTimePassedToSwitchToNonAimState(m_ped, Mathf.Max(this.AimAnimMaxTime, PedManager.Instance.minTimeToReturnToNonAimStateFromAimState))) return false; if ( !m_ped.IsAimOn ) diff --git a/Assets/Scripts/Behaviours/PedManager.cs b/Assets/Scripts/Behaviours/PedManager.cs index 86714191..bcc0b3d4 100644 --- a/Assets/Scripts/Behaviours/PedManager.cs +++ b/Assets/Scripts/Behaviours/PedManager.cs @@ -21,7 +21,7 @@ namespace SanAndreasUnity.Behaviours public FocusPointParameters npcPedFocusPointParameters = FocusPointParameters.Default; public float minTimeToReturnToAimState = 0.33f; - public float minTimeToReturnToNonAimStateFromAimState = 0.33f; + public float minTimeToReturnToNonAimStateFromAimState = 0.25f; public float timeUntilMovementStateCanBeSwitchedToOtherMovementState = 0.166f; public float timeUntilMovementStateCanBeEnteredFromOtherMovementState = 0.166f; public float timeUntilAimMovementStateCanBeSwitchedToOtherAimMovementState = 0.166f;