Files

29 lines
801 B
C#
Raw Permalink Normal View History

2026-05-26 09:46:57 +07:00

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;
}
}
}