Net.Like.Xue.Tokyo/Assets/BITKit/UnityPluginsSupport/FPS/SpringEulerAngle.cs

38 lines
1012 B
C#
Raw Normal View History

2024-11-03 16:42:23 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
[System.Serializable]
public class SpringEulerAngle
{
public float damp = 20;
public float frequence = 15;
[HideInInspector]
public Vector3 value = Vector2.zero;
Vector3 dampValue = Vector2.zero;
public void Clear()
{
value = Vector2.zero;
dampValue = Vector2.zero;
}
public void Update(float deltaTime, Vector3 target)
{
value -= dampValue * deltaTime * frequence;
dampValue = eulerLerp(dampValue, value - target, deltaTime * damp);
}
public static Vector3 eulerLerp(Vector3 left, Vector3 right, float t)
{
Vector3 ret;
ret.x = Mathf.LerpAngle(left.x, right.x, t);
ret.y = Mathf.LerpAngle(left.y, right.y, t);
ret.z = Mathf.LerpAngle(left.z, right.z, t);
return ret;
}
}
}