Entities/SkatePushVolume.cs

A trigger volume that applies push forces to entities, specialized for this game's skater controller. It looks up a SkateController on the collided entity and, if present and allowed, applies external velocity via the controller; otherwise it falls back to the base PushVolume behavior.

Networking
using LegacyEntityPack;
using Skateboard.Player;

namespace Skateboard.Entities;

/// <summary>
/// Push volume that also pushes the skater. Inherits the generic <see cref="PushVolume"/>
/// and routes pushes through this game's <see cref="SkateController"/>.
/// </summary>
[Title( "Push Volume (Skate)" )]
[Category( "Skateboard/Triggers" )]
[Icon( "deblur" )]
public sealed class SkatePushVolume : PushVolume
{
	protected override void Push( Collider other, float time )
	{
		var controller = other.Components.Get<SkateController>( FindMode.EverythingInSelfAndAncestors );
		if ( controller.IsValid() )
		{
			if ( !PushedThisTick.Add( controller.GameObject ) )
				return;
			if ( Networking.IsActive && controller.Network.IsProxy )
				return;

			controller.AddExternalVelocity( GetForce( time ) );
			return;
		}

		// Fall back to Rigidbody / CharacterController handling for everything else.
		base.Push( other, time );
	}
}