apply initial velocity to destroyed vehicle parts

This commit is contained in:
in0finite 2021-12-27 01:29:44 +01:00
parent 8ddcb62ac8
commit 08c46da0bd

View file

@ -238,10 +238,28 @@ namespace SanAndreasUnity.Behaviours.Vehicles
void DetachFrameDuringExplosion(Frame frame, float mass, GameObject parentGo)
{
DetachFrameFromTransformDuringExplosion(this.transform, frame, mass, parentGo, this.NetIdentity.netId, this.Definition.Id, this.Colors);
DetachFrameFromTransformDuringExplosion(
this.transform,
frame,
mass,
parentGo,
this.NetIdentity.netId,
this.Definition.Id,
this.Colors,
this.RigidBody != null ? this.RigidBody.velocity : (Vector3?)null,
this.RigidBody != null ? this.RigidBody.angularVelocity : (Vector3?)null);
}
public static void DetachFrameFromTransformDuringExplosion(Transform tr, Frame frame, float mass, GameObject parentGo, uint vehicleNetId, int vehicleModelId, IReadOnlyList<Color32> vehicleColors)
public static void DetachFrameFromTransformDuringExplosion(
Transform tr,
Frame frame,
float mass,
GameObject parentGo,
uint vehicleNetId,
int vehicleModelId,
IReadOnlyList<Color32> vehicleColors,
Vector3? initialVelocity = null,
Vector3? initialAngularVelocity = null)
{
if (! tr.IsParentOf(frame.transform)) // already detached ?
return;
@ -269,6 +287,10 @@ namespace SanAndreasUnity.Behaviours.Vehicles
rigidBody.drag = 0.05f;
rigidBody.maxDepenetrationVelocity = VehicleManager.Instance.explosionLeftoverPartsMaxDepenetrationVelocity;
rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
if (initialVelocity.HasValue)
rigidBody.velocity = initialVelocity.Value;
if (initialAngularVelocity.HasValue)
rigidBody.angularVelocity = initialAngularVelocity.Value;
if (NetStatus.IsServer)
{