fix impact gib velocity (#3513)

This commit is contained in:
Layla
2025-12-01 09:28:15 +00:00
committed by GitHub
parent ac798c9be1
commit abfa79f610
2 changed files with 22 additions and 3 deletions

View File

@@ -332,7 +332,7 @@ sealed public partial class Rigidbody : Component, Component.ExecuteInEditor, IG
if ( !EnableImpactDamage ) return;
if ( IsProxy ) return;
var speed = collision.Contact.Speed.Length;
var speed = collision.Contact.NormalSpeed;
var minSpeed = MinImpactDamageSpeed;
if ( minSpeed <= 0 )
minSpeed = 500f;
@@ -477,10 +477,23 @@ sealed public partial class Rigidbody : Component, Component.ExecuteInEditor, IG
/// </summary>
internal Transform? TargetTransform { get; set; }
/// <summary>
/// Linear velocity before physics step. Internal until someone needs them.
/// </summary>
internal Vector3 PreVelocity { get; private set; }
/// <summary>
/// Angular velocity before physics step. Internal until someone needs them.
/// </summary>
internal Vector3 PreAngularVelocity { get; private set; }
void IScenePhysicsEvents.PrePhysicsStep()
{
if ( !_body.IsValid() ) return;
PreVelocity = _body.Velocity;
PreAngularVelocity = _body.AngularVelocity;
if ( TargetTransform.HasValue )
{
// Editor transform uses velocity to move.

View File

@@ -550,8 +550,14 @@ public class Prop : Component, Component.ExecuteInEditor, Component.IDamageable
if ( phys is not null && rb is not null )
{
phys.Velocity = rb.Velocity;
phys.AngularVelocity = rb.AngularVelocity;
// Compute linear velocity at the gibs spawn point.
var velocity = rb.PreVelocity + Vector3.Cross( rb.PreAngularVelocity, phys.MassCenter - rb.MassCenter );
// Apply 50% energy loss.
velocity *= 0.5f;
phys.Velocity = velocity;
phys.AngularVelocity = rb.PreAngularVelocity;
}
}