- Home /
Exploding two gameobjects from the center of an collision
I have two GameObjects that collides and when they do that I want to add an explosionforce at the position (center?) of the collision to make them "explode" away from each other. Is this data stored in the Collision or is there an easy way of calculating it?
float explosionForce = 300.0f; float explosionRadius = 6.0f; float explosionUpwardsModifier = 0.0f; Vector3 explosionPosition = ?;
rigidbody.AddExplosionForce(explosionForce, explosionPosition, explosionRadius, explosionUpwardsModifier);
Answer by Cyb3rManiak · May 11, 2011 at 11:47 AM
Check out the example code at MonoBehaviour.OnCollisionEnter. You can use the collision info returned to get the collision points between the two objects (which is what the example shows by drawing rays). Also, there's another one at Collider.OnCollisionEnter.
Your answer
Follow this Question
Related Questions
How to collide with everything but trigger script whenever certain object hits 1 Answer
How to achieve this basic physics effect? Detect when to change layers 2 Answers
Physics explosion when pausing during collision 1 Answer
[SOLVE] 2D Space shooter - explosion power-up scripting, please help! 1 Answer