Files
OnlyNPC/Assets/FPS/Scripts/Gameplay/PositionBobbing.cs
manhduyhoang90 167a617e09 asdasd
2026-05-26 09:46:57 +07:00

29 lines
801 B
C#

using UnityEngine;
namespace Unity.FPS.Gameplay
{
public class PositionBobbing : MonoBehaviour
{
[Tooltip("Frequency at which the item will move up and down")]
public float VerticalBobFrequency = 1f;
[Tooltip("Distance the item will move up and down")]
public float BobbingAmount = 0.5f;
Vector3 m_StartPosition;
void Start()
{
// Remember start position for animation
m_StartPosition = transform.position;
}
void Update()
{
// Handle bobbing
float bobbingAnimationPhase = ((Mathf.Sin(Time.time * VerticalBobFrequency) * 0.5f) + 0.5f) * BobbingAmount;
transform.position = m_StartPosition + Vector3.up * bobbingAnimationPhase;
}
}
}