- Home /
Colliding with Terrain and Destroying it
I'm trying to Destroy a terrain when an object flies into it.
The object is a cube, it's set to 'is trigger', has a rigid body that listens to gravity, and has a script that looks like this:
function OnTriggerEnter ( other : Collider )
{
print ("YES1");
Destroy ( other );
if( other.gameObject.tag == "Terrain")
{
Destroy ( other );
Destroy ( this );
print ("YES2");
}
}
When I drop the Cube onto the Terrain piece, "YES1" is printed to the console, meaning that the collision IS detected. But at no point does the terrain piece disappear. Help!
:(
Answer by paulaceccon · Jan 30, 2013 at 10:50 PM
other is just the collider of your terrain. Have you tried:
Destroy ( other.gameObject );
??
No, but I'll try that when I get home. Thanks. Also, this script is attached to a Cube and I want to destroy the Cube as well... so would I write:
Destroy ( this.gameObject ) ;
?
I implemented this and it worked AL$$anonymous$$OST perfectly. Occasionally the Cube would just fall through the Terrain. I might try and switch it to continuous?
Switching it to continuous seems to have solved the problem. Yay :)
Your answer
Follow this Question
Related Questions
Triggers not working 2 Answers
OnTriggerEnter problems 3 Answers
OnTriggerEnter problem 2 Answers
Do continuous and continuous dynamic collision detection work with trigger colliders? 1 Answer