A pickup item component that gives the owning Car a temporary speed boost. It validates the owner's Movement, starts a drift boost for a configured Duration, spawns a visual boost effect if the car has a Drift component, then destroys the pickup object.
using Machines.Player;
namespace Machines.Items;
/// <summary>
/// Pickup that gives the user a sustained speed boost
/// </summary>
public sealed class BoostItem : Component, IPickupItem
{
/// <summary>
/// How long the boost lasts (seconds).
/// </summary>
[Property]
public float Duration { get; set; } = 3f;
public bool Activate( Car owner )
{
if ( !owner.Movement.IsValid() )
return false;
owner.Movement.StartDriftBoost( CarDrift.DriftBoostSpeed, Duration );
owner.Drift?.SpawnBoostEffect();
// Boost is on the car; nothing to keep alive here.
GameObject.Destroy();
return true;
}
}