- Home /
ignore triggers
looking for a simple way to say i want this trigger to ignore certain objects. so say i have a human with colliders on him which are triggers and one of them activates something when it hits or gets hit. the only problem though is if one of these triggers touch each other it activates the other thing..
i was going to say if this trigger hits the certain thing then it activates but there are a lot of different things in my game that activates this
so basically need a bit of code which simply says ignore this object/trigger..
i know how to ignore collisions but this is no good as it adds unwanted movement to the character and extra weight.
Answer by Kryptos · Jan 15, 2012 at 11:29 PM
To achieve that you have to use a good combination of layers. And set their relation regarding Physx properly. See http://unity3d.com/support/documentation/Components/Layer%20Based%20Collision%20detection.html
Note that you can change the layer of any object (and child object) at runtime so they might fall into one or another category (colliding, not-colliding...).
i will have a look at this and compare which is better, its probably more efficiant than above. have to see with the next part of the game. basically when my trigger does hit something i want all my triggers to turn back into colliders..
Answer by reptilebeats · Jan 15, 2012 at 11:29 PM
got it its
Physics.IgnoreCollision(collider, transform.gameObject.Find("").collider);
if anyones got anything better let me know
Answer by aldonaletto · Jan 15, 2012 at 11:39 PM
You can place objects in different layers and define the Collision Matrix, so objects in one layer can collide only with objects in other specific layers, but more frequently you just use special tags to identify the objects that can be activated, collected etc.:
function OnTriggerEnter(other: Collider){ if (other.CompareTag("Switch")){ // use CompareTag... // call Activate(true) in the other object's script other.SendMessageUpwards("Activate", true); } if (other.tag == "Bonus50"){ // or compare the string directly Inventory.bonus += 50; // count points in a static variable... audio.PlayOneShot(bonusSound); // play the appropriate sound... Destroy(other.gameObject); // destroy the picked object } }
function OnTriggerEnter(other: Collider){ if (other.CompareTag("Switch")){ // call Activate(false) in the other object's script other.SendMessageUpwards("Activate", false); } } This way you can take the appropriate actions for each kind of object.
Your answer
Follow this Question
Related Questions
Can Physics.IgnoreCollision disable OnTrigger... events? 2 Answers
Colliders overlapping with trigger colliders 1 Answer
A child component is triggering its parent collider. 1 Answer
Trigger still works when disabled 1 Answer
Get Object, Trigger Attached Method,Trigger method on collider script 1 Answer