Component that rotates its GameObject around a configurable axis at a constant angular speed. It increments an internal angle each update and applies a world rotation from the axis and angle, used for making falling power-ups tumble.
using Sandbox;
namespace Breakout;
/// <summary>
/// Slowly spins whatever it's attached to around an axis. Used to make falling power-ups tumble.
/// </summary>
public sealed class Spinner : Component
{
[Property] public float SpinSpeed { get; set; } = 90f;
[Property] public Vector3 SpinAxis { get; set; } = Vector3.Up;
float currentAngle = 0f;
protected override void OnUpdate()
{
base.OnUpdate();
currentAngle += SpinSpeed * Time.Delta;
currentAngle %= 360f;
GameObject.WorldRotation = Rotation.FromAxis( SpinAxis, currentAngle );
}
}