- Home /
How to make BoxColidier to have transparent side?
Hello everybody, this question is so hard to explain... So from this picture i think you will understand.. So on the picture we have 1 field which is marked by BoxColidiers but 2D . So when we have object inside of the field, object can't go out from the field (For that i use BoxColidier2D). But when object coming from the outside of field, it can enter to the field :) Please if you understand what should i do? A picture is attached.. Thank you!![![alt text][2]][3]
Answer by AmunTech · Sep 27, 2014 at 07:02 PM
You can set the bottom collider as trigger, this let the obect pass, and with a simple script you can activate it when the object pass through, something like this:
void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "ObjectTagHere"){
GetComponent<Collider2D>().isTrigger = false;
}
}
or
void OnTriggerExit2D(Collider2D other) {
if(other.tag == "ObjectTagHere"){
GetComponent<Collider2D>().isTrigger = false;
}
}
Yes, you need to set as trigger the collider in the inspector by checking isTrigger, and put this script on that gameobject
Collider of my object or Collider of field? And i did BoxCollider2D
Collider of field, the collider of the object where your object need to pass through. And sorry i forgot you are using 2D so i edited the above code.
O$$anonymous$$ so this is the code what i set in:
void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Respawn"){
GetComponent<Collider2D>().isTrigger = false;
}
}
void OnTriggerExit2D(Collider2D other) {
if(other.tag == "Respawn"){
GetComponent<Collider2D>().isTrigger = false;
}
}
"Respawn" is tag of the sides of the field. Now i set is trigger checked and nothing still working.. I'm trying to make code that will allow object which is co$$anonymous$$g out from the field to enter the field. But when object is trying to left field, it can't . As on the picture. I tried so much combinations and still nothing :/
Your answer
Follow this Question
Related Questions
RayCasts and BoxCollider2D not working? 2 Answers
How can I fix animations that are too high or too low without moving the box collider? 0 Answers
How can i detect which side of a box collider 2D the collider object collided with? 2 Answers
Boxcollider2D, Trigger not working 2 Answers
Problem with 2D collision detection (Wide object falls through a thin hole) 1 Answer