Player/PlayerPawn.Death.cs
public sealed partial class PlayerPawn
{
/// <summary>
/// Spawns a physics ragdoll copy of the ship that flies, spins, then explodes.
/// Called via Rpc.Broadcast so all clients see it.
/// </summary>
[Rpc.Broadcast]
public void CreateDeath()
{
var model = ModelRenderer?.Model;
if ( model == null ) return;
var ragdoll = new GameObject( true, "Ship Ragdoll" );
ragdoll.WorldPosition = WorldPosition;
ragdoll.WorldRotation = WorldRotation;
var renderer = ragdoll.Components.Create<SkinnedModelRenderer>();
renderer.Model = model;
// Copy material override / skin if present
if ( ModelRenderer is SkinnedModelRenderer smr && smr.MaterialOverride != null )
renderer.MaterialOverride = smr.MaterialOverride;
var ragdollComp = ragdoll.Components.Create<ShipRagdoll>();
// Inherit current ship velocity + a strong random kick
ragdollComp.LinearVelocity = Velocity * 1.5f + Vector3.Random.WithZ( 0 ) * 2000f;
// Fast dramatic tumble
ragdollComp.AngularVelocity = new Vector3(
Game.Random.Float( -400f, 400f ),
Game.Random.Float( -400f, 400f ),
Game.Random.Float( -600f, 600f ) );
ragdollComp.ExplosionPrefab = Data?.ExplosionPrefab;
}
}