32 lines
924 B
C#
32 lines
924 B
C#
using UnityEngine;
|
|
|
|
public class ShipPhysics : MonoBehaviour {
|
|
ShipControls ship;
|
|
|
|
float maxDmg = 150f;
|
|
float maxImpulse = 5000f;
|
|
|
|
void Awake() {
|
|
ship = GetComponent<ShipControls>();
|
|
}
|
|
|
|
void OnCollisionEnter(Collision collision) {
|
|
float totalForce = collision.impulse.magnitude / Time.fixedDeltaTime;
|
|
|
|
Debug.Log($"mag {collision.relativeVelocity.magnitude}");
|
|
Debug.Log($"impulse {collision.impulse} {collision.impulse.magnitude} {totalForce}");
|
|
|
|
// if (collision.relativeVelocity.magnitude > maxDmg) {
|
|
if (totalForce > maxImpulse) {
|
|
Debug.Log("Ddddestroyed by" + collision.gameObject.name);
|
|
ship.Respawn();
|
|
return;
|
|
}
|
|
|
|
if (collision.gameObject.tag == "TrackLimits") {
|
|
Debug.Log("Track Limits " + collision.gameObject.name);
|
|
ship.Respawn();
|
|
return;
|
|
}
|
|
}
|
|
} |