I’m trying to destroy a game object only if the player comes within range of a sphere trigger attached to the object I use
function OnTriggerEnter(other : Collider){
print("Item Destroyed");
}
but it would be destroyed as it fell to the ground because the terrain’s collider sets it off…
Thanks.
I ran into something similar when first learning Unity. I wanted the basic same thing… on collision with player, destroy object. I fixed it with a hack’ish solution, but it worked.
First, I made another js. named something like “canCollideScript”. I put that script on the Player object. Then I wrote the script on the object I wanted to destruct when it collided with the player object to look like this:
function OnTriggerEnter(other : Collider){
if (other.GetComponent(canCollideScript))
{
print(“Item Destroyed”);
}
}
Basically, when anything collided with the trigger, it checked to see if what it was colliding with had the “canCollideScript”. If it did, then it destroyed itself. If it did not, it ignored the collision.
Like I said, this is a pretty hack’ish way of doing it, though. A cleaner way would be to use tags on the player object and use gameObject.tag instead of the GetComponent.
I am sure the more skilled scripters/programmers out there have an even cleaner way of doing it. I know there is a way to make an object ignore certain collisions. Just thought I would give you a simple solution, for now. Truly hope it helps.
Louis “Gryphon” Crochet
Chaotic Heart Studios
I think the easiest way of solving this problem is to give your objects that you DO want to register as a collision “tags” and check the tag of an object before doing anything.
Thanks guy’s lots of help thanks again for the replies