- Home /
Collider OnTriggerEnter not working
I have 2 objects a lazer and an asteroid, on the lazer object I have a small lazer hit script which is just
#pragma strict
function OnTriggerEnter(other : Collider) {
Destroy(other.gameObject);
}
The settings of my box collider are : is trigger = true center : 0,0,0 size = 5,5,1 Material = none
The settings of my asteroid sphere collider are: is trigger = false center = 0,0,0 radius = 500 material = none
I really do not have any idea why this does not work. I have tried almost everything. The lazer only moves with the ship which travels under 70m/s The asteroids are stationary. This question probably came up a lot but none of the answers worked for me. I have not tried ray casts yet though.
I don't think they both need to be triggers. Also, they both need to be 3D objects (have non-2D colliders).
Try setting only the box collider on the asteroid as a trigger. Also, make sure they are hitting each other. ( are in the same plane)
I am sure they are hitting each other and they are already 3d colliders, only one of them has their trigger enabled. And it still doesnt work if i change them around.
Lazers are really fast and their trajectory is straight. Fast objects and collision detection is a bit tricky, you should use Physics.Raycast ins$$anonymous$$d.
Im sure i had this issue with triggers destroying object. try putting it to OnCollisionEnter and take of the trigger check box on the collider on game object.
Did this work?