Animations/ShakeAnimation.cs
using System;
namespace BetterUI.Animations;
/// <summary>
/// Animates a component by shaking it between a minimum and maximum position.
/// </summary>
public class ShakeAnimation : AnimationBase
{
/// <summary>
/// The intensity of the shake animation.
/// </summary>
[Property]
public float Intensity { get; set; } = 1f;
/// <summary>
/// The frequency of the shake animation.
/// </summary>
[Property]
public float Frequency { get; set; } = 1f;
protected override void OnAnimate( float t )
{
var easedTime = ApplyEasing( NormalizedTime, Easing );
var shakeFactor = MathF.Sin( easedTime * MathF.PI * 2 * Frequency );
var x = StartPosition.x + (Axis.x * shakeFactor * Intensity);
var y = StartPosition.y + (Axis.y * shakeFactor * Intensity);
var z = StartPosition.z + (Axis.z * shakeFactor * Intensity);
WorldPosition = new Vector3( x, y, z );
}
}