Functional/FuncRotate.cs

A component that smoothly rotates its entity toward a target orientation. It exposes a target Angles property (ToTranslate), a Speed, and a debug State; when StartRotating is called it lerps WorldRotation toward ToTranslate on fixed updates.

using Sandbox;

[Category( "Functional" )]
[Icon( "double_arrow" )]
public sealed class FuncRotate : Component
{
	enum RotateState
	{
		None = 0,
		Moving = 1
	}

	[Property]
	Angles ToTranslate { get; set; }

	[Property]
	float Speed { get; set; } = 1F;

	[Property, Group( "Debug" ), ReadOnly]
	RotateState State { get; set; } = RotateState.None;

	protected override void OnFixedUpdate()
	{
		if ( State == RotateState.Moving )
			WorldRotation = Rotation.Lerp( WorldRotation, ToTranslate, Time.Delta * Speed );

		if ( WorldRotation.AlmostEqual( ToTranslate, 0.001f ) )
		{
			WorldRotation = ToTranslate;
			State = RotateState.None;
		}
			

		base.OnFixedUpdate();
	}

	public void StartRotating()
	{
		State = RotateState.Moving;
	}
}