Help with Collision Detection for explosions?

Hey guys

I’m making a simple action where a spaceship needs to collide with an asteroid, and the code I’m using for it is here:

var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision) {
 
    var contact : ContactPoint = collision.contacts[0];
    var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal);
    var pos : Vector3 = contact.point;
    Instantiate (explosionPrefab, pos, rot); 
    Destroy (gameObject);
}

I personally can’t see anything wrong with this, as I’ve set both the spaceship and the object with non-kinematic RigidBodies, and Unity doesn’t warn me of any scripting mistakes, but whenever I try to crash into an asteroid, the ship goes right through it, with no explosion effect. Can someone please help me with this, as I need the project to be submitted later today?enter code here

Thanks

Harry

Are both objects on layers that are configured for collision detection? (Check in Edit > Project Settings > Physics.)

Do they both have colliders in addition to rigidbodies? The simpler the collider, the faster your game will run. Try adding a sphere collider to the asteroid and maybe a box collider to the ship.

Also, add a Debug.Log() line inside OnCollisionEnter() to make sure that the function is actually getting called.