- Home /
Trigger Collider not detecting game objects?
Hi, I'm making a game where a marker tracked by a camera can be used to manipulate the game environment. To do this, I have an object that moves in relation to this marker in 2D space. In order to pick up objects behind the marker (in 3D space), I have attached a box trigger collider to it to detect objects in the same x,y co-ordinates at different depths. However, I'm having issues getting it to detect anything.
function OnTriggerEnter (other: Collider) { //if ( other.gameObject.layer == "moveable" ) Debug.Log ("Object Found"); }
function OnTriggerStay (other : Collider) { }
function OnTriggerExit (other : Collider) { Debug.Log ("Object Not Found"); }
This is my code attached to the trigger box, which seems pretty standard as far I can tell. At the minute, I have several crates and the lerpz character from the 2D game tutorial in my scene. The trigger only detects lerpz, and cannot find any of the crates when they collide with it. If I activate the code which also searches for the layer tag, it can no longer sends out the "Object Found" message for anything, even Lerpz. It does however still send out the "Object Not Found message when he moves out of it.
So the things I'm struggling with: 1. Why won't the trigger detect the crates? They're rigidbodies with box colliders. 2. Why can it detect lerpz? Lerpz doesnt seem have a collider at all, and I thought both objects needed on for a trigger to activate. 3. Why can I no longer get the Object Found message when I add the code for seperate layers? Why does it still give me the object not found?
All help would be appreciated! Thanks!
Your answer
Follow this Question
Related Questions
Simple Triggers problem. 1 Answer
Rigidbody2D alternating between TriggerEnter and TriggerExit? 1 Answer
isKinematic rigidbody collisions 3 Answers
col.gameObject.layer is not working 1 Answer
Layers, parenting and collisions. 0 Answers