Park/Rides/FlatRides/BoatSwingRide.cs
using HC3;
using System;
public sealed class BoatSwingRide : BasicRide
{
[Property] public GameObject RideBoat { get; set; }
private float maxSwingAngle = 45f;
private float swingFrequency = 0.5f;
private float elapsed = 0f;
private float rideEndEaseTime = 3.0f;
protected override void DrawGizmos()
{
base.DrawGizmos();
if ( RideBoat == null )
return;
Gizmo.Draw.IgnoreDepth = true;
Gizmo.Draw.LineThickness = 4;
Gizmo.Draw.Color = Color.Orange;
Gizmo.Draw.LineSphere( RideBoat.WorldPosition, 10f );
}
protected override void OnUpdate()
{
base.OnUpdate();
if ( !RideStarted || RideBoat == null )
return;
elapsed += Time.Delta;
float progress = elapsed / RideLength;
float strength = 1.0f;
if ( progress > 1.0f - (rideEndEaseTime / RideLength) )
{
float endProgress = (progress - (1.0f - (rideEndEaseTime / RideLength))) / (rideEndEaseTime / RideLength);
strength = MathX.Lerp( 1.0f, 0.0f, endProgress );
}
else
{
strength = MathF.Min( 1.0f, progress );
}
float angle = MathF.Sin( Time.Now * swingFrequency * MathF.Tau ) * maxSwingAngle * strength;
RideBoat.LocalRotation = Rotation.FromAxis( Vector3.Right, angle );
}
[Button( "Start Ride" )]
protected override void OnRideStarted()
{
base.OnRideStarted();
elapsed = 0f;
if ( RideBoat != null )
{
RideBoat.LocalRotation = Rotation.Identity;
}
}
}