From 277d8f47c8190509862c0ced7cc445494208f668 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 17 Oct 2021 21:00:35 +0200 Subject: [PATCH] smooth out drive-by anim changing --- .../Behaviours/Ped/States/DriveByState.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs index f66f0c2f..43ce0b43 100644 --- a/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs +++ b/Assets/Scripts/Behaviours/Ped/States/DriveByState.cs @@ -48,14 +48,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States } private float m_lastTimeWhenDeactivated = 0f; + public float timeUntilAbleToSwitchState = 0.5f; - public float timeUntilAbleToSwitchState = 0.3f; + private float m_lastTimeWhenChangedAnim = 0f; + private string m_lastAnim = null; + public float timeUntilAbleToChangeAnim = 0.5f; public override void OnBecameInactive() { m_lastTimeWhenDeactivated = Time.time; + m_lastAnim = null; base.OnBecameInactive(); } @@ -107,7 +111,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States { if (this.CurrentVehicleSeat != null) { - var animId = new Importing.Animation.AnimId("drivebys", this.GetAnimBasedOnAimDir()); + var animId = new Importing.Animation.AnimId("drivebys", this.GetAnimBasedOnAimDirSmoothed()); m_model.PlayAnim(animId); m_model.LastAnimState.wrapMode = WrapMode.ClampForever; @@ -126,6 +130,17 @@ namespace SanAndreasUnity.Behaviours.Peds.States } } + string GetAnimBasedOnAimDirSmoothed() + { + if (m_lastAnim != null && Time.time - m_lastTimeWhenChangedAnim < this.timeUntilAbleToChangeAnim) + return m_lastAnim; + + m_lastTimeWhenChangedAnim = Time.time; + + m_lastAnim = this.GetAnimBasedOnAimDir(); + return m_lastAnim; + } + string GetAnimBasedOnAimDir() { // 4 types: forward, backward, same side, opposite side