Question by
$$anonymous$$ · Dec 14, 2017 at 05:18 PM ·
collisioncrashdetection
Crash detect
Hi guys,
I'm making car game in unity3d, I have city, cars, street lamps etc. I want to make it destroyable, like in GTA. For now its working like it should be, but problem is with resistance of some object, for example traffic lights or lamps, objects which are concreted.
Here is picture which is describing it:
Here is my script, its really easy and its working in low speed (<60-70kmh):
private void OnCollisionEnter(Collision collision)
{
PlayerSpeed = gameObject.GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
PlayerMass = gameObject.GetComponent<Rigidbody>().mass;
PlayerKineticEnergy = (PlayerMass * PlayerSpeed * PlayerSpeed) / 2;
if (PlayerKineticEnergy > 900000.0f)
{
collision.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
StreetBehaviour = collision.gameObject.GetComponent<Street_Asc_Behaviour>();
CollisionSpeed = Mathf.Sqrt((2 * 900000) / (PlayerMass));
gameObject.GetComponent<Rigidbody>().AddForce(transform.forward * (-CollisionSpeed * StreetBehaviour.ObjectResistance), ForceMode.Impulse);
}
}
As you can see, im using freeze position and rotation in rigidbody, its working very well in low speed. In high speed it doesnt detect collision.
So if you have better one, it would be great :)
Thanks
crash.jpg
(101.1 kB)
Comment