Animations/BounceComponent.cs
using System;
namespace BetterUI.Animations;
/// <summary>
/// A bounce animation that moves the target in a sine wave motion.
/// </summary>
public class BounceAnimation : AnimationBase
{
/// <summary>
/// The amplitude of the bounce.
/// </summary>
[Property]
public float Amplitude { get; set; } = 10f;
/// <summary>
/// The range of the bounce.
/// </summary>
[Property]
public Vector2 Range { get; set; } = new Vector2( 0f, 10f );
/// <summary>
/// The frequency of the bounce.
/// </summary>
[Property]
public float BounceFrequency { get; set; } = 1f;
protected override void OnAnimate( float t )
{
var easedTime = ApplyEasing( NormalizedTime, Easing );
var range = Range.y - Range.x;
var value = Range.x + range * (0.5f + 0.5f * MathF.Sin( easedTime * MathF.PI * 2 * BounceFrequency ));
var x = StartPosition.x + (Axis.x * value);
var y = StartPosition.y + (Axis.y * value);
var z = StartPosition.z + (Axis.z * value);
WorldPosition = new Vector3( x, y, z );
}
}