Files
CartoonFPS/Assets/FPS Framework/Scripts/Animation System/SpringVector3.cs
2025-08-06 23:18:38 +01:00

40 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Akila.FPSFramework.Animation
{
[System.Serializable]
public class SpringVector3
{
public Vector3 value;
public float speed = 10;
public float fadeOutTime = 1;
[Range(0, 1)] public float weight = 1;
public float time { get; set; }
public float progress { get; set; }
public Vector3 result { get; set; }
private float velocity;
public void Update(float globalSpeed)
{
time += Time.deltaTime * speed * globalSpeed;
float pos = 0;
pos += Mathf.Sin(time) * progress;
progress = Mathf.SmoothDamp(progress, 0, ref velocity, fadeOutTime / globalSpeed);
result = new Vector3(pos * value.x, pos * value.y, pos * value.z) * progress;
}
public void Start(Vector3 value)
{
this.value = value;
progress = 1 * weight;
time = 0;
}
}
}