mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
fix impact gib velocity (#3513)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user