BITFALL/Assets/BITKit/UnityPluginsSupport/FPS/Spring3.cs

30 lines
870 B
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using System;
2023-06-08 14:09:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.FPS
{
2023-10-20 19:31:12 +08:00
[Serializable]
2023-06-08 14:09:50 +08:00
public class Spring3
{
public Vector3 value = Vector2.zero;
2023-10-20 19:31:12 +08:00
[SerializeField] private Vector3 dampValue = Vector2.zero;
[SerializeField] private float damp = 1;
[SerializeField] private float frequence = 1;
2023-06-08 14:09:50 +08:00
public void Clear()
{
value = Vector2.zero;
dampValue = Vector2.zero;
}
public Spring3(float damp, float frequence)
{
this.damp = damp;
this.frequence = frequence;
}
public void Update(float deltaTime, Vector3 target)
{
value -= dampValue * deltaTime * frequence;
dampValue = Vector3.Lerp(dampValue, value - target, deltaTime * damp);
}
}
}