- Home /
Why won't the collision work?
#pragma strict
function OnCollisionEnter(hitIt : Collision) {
Destroy(hitIt.gameObject);
}
I am trying to make a another primitive sphere be destroyed when it collides with this one. Both spheres have a collider and this one is a trigger. The other has rigid body. I tried changing something in the script and I got a compiling error so I know it's using the script.
Thanks to both of you. I realized after I posted this that the trigger was the problem.
Answer by DryTear · Feb 04, 2013 at 04:04 AM
OnCollision functions use (col : Collision){ - and it does not need to be isTrigger
OnTrigger functions use (col : Collider){ - This one needs to be isTrigger
That means that none of those two SphereObjects need to be checked as isTrigger
Answer by gribbly · Feb 04, 2013 at 05:45 AM
If this is the script attached to the trigger, you want to do this instead:
function OnTriggerEnter(hitIt : Collider){
Destroy(hitIt.gameObject);
}
Reason: Collider components set to be "trigger" send the OnTriggerEnter message, not the OnCollisionEnter message.
Answer by Ermarrero · Apr 07, 2014 at 01:58 AM
Also make sure one of the colliding objects have a rigidbody attached.
Please don't necro answer a post like this; nearly a year later and after a thank-you from OP that is was resolved...
huh?? not sure what your talking about but I added that comment for the simple fact that most newbies forget to add a rigidbody and then their ontrigger event does not work.
$$anonymous$$aybe you didn't notice the date. We don't go back and add such comment/answer to every 'how do I access var from script b in script a' either.
Your answer
Follow this Question
Related Questions
On Click, destroy object and any colliding object with the same tag. 6 Answers
Zombie Health Script Not working?? 1 Answer
Collider to Delete Object 1 Answer
Prevent instantiating on collider 1 Answer
Destroy cube on collision 1 Answer