- Home /
Collision flag entering a tagged object's collider
How to detect when a character controller's collision flag enter an specifically tagged object's trigger collider?
Within the OnTriggerEnter or OnCollisionEnter place:
if(GameObject.tag = "Name of tag") {}
Answer by SlainPriest · Jul 09, 2012 at 06:21 AM
like this:
//i'm assuming you're setting this in the editor
var myTag : String;
function OnTriggerEnter(col : Collider){
//get the object of the collider we just hit
var obj : gameObject = col.gameObject;
//compare it's tag to the one we want
if(obj.tag == myTag){
doThings();
}
}
What i want isn't detect a simple collision, i want to detect the collision of an specifically tagged object with a specific collision flag of the character controller. CollisionFlags.Above for exemple.
This does that, we're just finding the tag after we hit something. You can also use layers for collision, so only the objects that you set (for this, go to edit>project settings>physics) will register collisions with each other. That might be more straightforward to what you are looking for.
Answer by Disastercake · Jul 09, 2012 at 06:21 AM
On the object with the collider make sure "is trigger" is checked in the inspector. Then attach a script that has the function OnTriggerEnter(). Inside this function you would do the IF statements to check if the tag is player of the entering collider.
You can see the documentation here: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
Your answer
Follow this Question
Related Questions
Help With Colliders 3 Answers
Collision Layer 2 Answers
handling collision with two objects of the same tag 1 Answer
Collision detection problem 1 Answer
handling collision with two objects of the same tag 1 Answer