38 lines
1012 B
C#
38 lines
1012 B
C#
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;
|
|
}
|
|
}
|
|
}
|