CounterTrayFlight.cs
using Sandbox;
namespace PaintballBaddies;
/// <summary>Local native physics: a shot flips the serving tray instead of deleting it.</summary>
public sealed class CounterTrayFlight : Component
{
private float age;
private int round;
private Vector3 launch;
public static void Spawn(Scene scene,Vector3 at,Rotation rotation,Vector3 direction,int round)
{
foreach(var old in scene.GetAllComponents<CounterTrayFlight>().ToArray())old.GameObject.Destroy();
var go=new GameObject(false,"Flying stainless serving tray"){NetworkMode=NetworkMode.Never,WorldPosition=at+Vector3.Up*2,WorldRotation=rotation};
go.Tags.Add("paintball_debris");go.Components.Create<ModelRenderer>().Model=Model.Load(RestaurantArena.BreakfastTray);
var collider=go.Components.Create<BoxCollider>();collider.Center=Vector3.Up*.4f;collider.Scale=new Vector3(24,32,1.2f);
var body=go.Components.Create<Rigidbody>();body.MassOverride=.3f;body.EnableImpactDamage=false;
var flight=go.Components.Create<CounterTrayFlight>();flight.round=round;flight.launch=direction*195+Vector3.Up*165;
go.Enabled=true;
Sound.Play(new SoundEvent{Sounds=[SoundFile.Load("sounds/physics/phys-impact-metal-sheet-001.vsnd")],Volume=.7f,Distance=900},at);
}
protected override void OnStart()
{
var body=Components.Get<Rigidbody>();body.Velocity=launch;body.AngularVelocity=new Vector3(4,7,2);
}
protected override void OnUpdate()
{
age+=Time.Delta;if(age>7 || MultiplayerSession.Find(Scene)?.RoundId!=round)GameObject.Destroy();
}
}