smooth out drive-by anim changing

This commit is contained in:
in0finite 2021-10-17 21:00:35 +02:00
parent beaf2d5484
commit 277d8f47c8

View file

@ -48,14 +48,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States
} }
private float m_lastTimeWhenDeactivated = 0f; 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() public override void OnBecameInactive()
{ {
m_lastTimeWhenDeactivated = Time.time; m_lastTimeWhenDeactivated = Time.time;
m_lastAnim = null;
base.OnBecameInactive(); base.OnBecameInactive();
} }
@ -107,7 +111,7 @@ namespace SanAndreasUnity.Behaviours.Peds.States
{ {
if (this.CurrentVehicleSeat != null) 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.PlayAnim(animId);
m_model.LastAnimState.wrapMode = WrapMode.ClampForever; 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() string GetAnimBasedOnAimDir()
{ {
// 4 types: forward, backward, same side, opposite side // 4 types: forward, backward, same side, opposite side