- Home /
Question by
Muzz 1 · May 14, 2011 at 02:28 PM ·
javascriptcollisionterrain
Collision with Terrain
Can you script OnCollisionEnter for a box collider and a terrain collider? Because it isn't working here. Do you have to use raycasts?
var explosion : GameObject;
function OnCollisionEnter (col : Collision) {
if(col.gameObject.name == "ground"){
Destroy (gameObject);
Instantiate (explosion, transform.position, transform.rotation);
}
}
Comment
You're destroying this gameObject before you Instantiate! that's what's wrong!
Answer by sneftel · May 14, 2011 at 03:14 PM
That looks like it should work. Make sure neither collider is set as a trigger.
I see what I did now. I used a small g ins$$anonymous$$d of a capital letter in ground.
Answer by Jesus_Freak · Jul 05, 2011 at 06:18 AM
var explosion : GameObject;
function OnCollisionEnter (col : Collision) {
if(col.gameObject.name == "ground"){
Instantiate (explosion, transform.position, transform.rotation);
Destroy (gameObject);
}
}
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Generated Terrain not colliding! HALP. 0 Answers
Trouble with a respawn script 1 Answer