- Home /
Moving Platforms and Collision
I have a bit of a largely complicated problem, but I have tried to simply it down to a much easier to understand concept.
Suppose that you are a player and there is a moving platform that goes between two ledges that you can walk on. Simple enough, however, you can't walk off the ledge when the platform isn't there. The platform has to be touching the ledge in order for the player to be able to walk off of the ledge, and onto the platform.
Essentially the question is about localized collision which can turn on and off. How could I make it so that the collision (let's just take a BoxCollider2D as an example in this context) disappears when the platform touches the ledge, then reappear when it's gone away from the ledge?
Thanks!
Edit: MS Paint example of Concept!
http://i1169.photobucket.com/albums/r505/Young-Griff/CollisionExample_zps67372f67.png
When the platform touches against one of the big orange squares, their respective green lines (collision) turn off and allow the player to pass through.
Answer by MrSoad · Oct 28, 2014 at 11:40 PM
Something like this should work on your ledge box collider object :
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "Platform_Trigger") {
collider.enabled = false;
}
}
function OnTriggerExit (other : Collider) {
if (other.gameObject.tag == "Platform_Trigger") {
collider.enabled = true;
}
}
You must parent/place a trigger onto your platform and tag it as "Platform_Trigger" for this to work.
Your answer
Follow this Question
Related Questions
Line Collision Detection for 2D Game 1 Answer
Calculating vectors for two colliding objects 1 Answer
AddForce not working on Rigidbody2D. 1 Answer
Collision is not detected ??? 0 Answers