- Home /
Collision Layer
How can I make a Cube with a Enemy tag on it to have a collider that can collide only certain objects.
Well heres the solution :
function Start () {
ignoreCollision("MyTag");
}
function ignoreCollision(tag : String) {
var objects = GameObject.FindGameObjectsWithTag(tag);
for (o in objects) {
if (o.GetComponent("Collider") && o != gameObject)
Physics.IgnoreCollision(collider, o.collider);
}
}
Felipe
Answer by asafsitner · Mar 12, 2012 at 11:21 PM
Yes, but instead of tags you should use layers. You can set the physics layers interaction under Edit -> Project Settings -> Physics
It would be nice if you provided your solution as answer and accepted it, then, so that future generations would benefit. :)
Answer by BigBlob · Mar 13, 2012 at 05:55 PM
Solution - I used a script that looks for the object with the certain tag and disables the collision.
function Start () {
ignoreCollision("Respawn");
}
function ignoreCollision(tag : String) {
var objects = GameObject.FindGameObjectsWithTag(tag);
for (o in objects) {
if (o.GetComponent("Collider") && o != gameObject)
Physics.IgnoreCollision(collider, o.collider);
}
}
Felipe
Your answer
Follow this Question
Related Questions
What's wrong with OnCollisionEnter? 2 Answers
Play annimation on collision not working. 1 Answer
OnCollision Script... 2 Answers
A limit to the number of tags? 2 Answers
Collision Issue 1 Answer