quakeball/Assets/Scripts/Animation/SoldierProceduralAnimator.cs

39 lines
1.4 KiB
C#
Raw Normal View History

2020-08-08 20:02:17 +02:00
using UnityEngine;
using NeonTea.Quakeball.Players;
namespace NeonTea.Quakeball.Animation {
/// <summary>Animates the parts that can't be animated via the animation system, e.g. aiming.</summary>
public class SoldierProceduralAnimator : MonoBehaviour {
public Transform Torso;
public Transform Head;
public Player Player;
private Vector3 TorsoBaseEulers;
private Vector3 HeadBaseEulers;
private Vector3 TorsoEulers;
private Vector3 HeadEulers;
private void Awake() {
TorsoEulers = TorsoBaseEulers = Torso.localEulerAngles;
HeadEulers = HeadBaseEulers = Head.localEulerAngles;
}
private void LateUpdate() {
float Yaw = Player.Yaw;
while (Yaw < -180) {
Yaw += 360;
}
while (Yaw > 180) {
Yaw -= 360;
}
Vector3 TargetTorsoEulers = TorsoBaseEulers + new Vector3(0, Yaw * 0.5f, 0);
TorsoEulers = Vector3.Lerp(TorsoEulers, TargetTorsoEulers, 10f * Time.deltaTime);
Torso.localEulerAngles = TorsoEulers;
Vector3 TargetHeadEulers = HeadBaseEulers + new Vector3(-Player.Pitch, Yaw * 0.5f, 0);
HeadEulers = Vector3.Lerp(HeadEulers, TargetHeadEulers, 10f * Time.deltaTime);
Head.localEulerAngles = HeadEulers;
}
}
}