- Home /
2D One-Way Stairs
So I have a 2D game and I need stairs that bring you to another floor but I want it to have another set of stairs in the opposite direct
ion.
I can't get the colliders for the stairs to disable when I'm coming from the back of them. I've tried using triggers to detect when you are behind the stair but it's not working properly. Is there an easy way to just detect from which direction you're colliding from. (Using edgeCollider for the top of the stairs)
I would be doing this with the colliders on the stairs being disabled by default and enabling on approach. In theory, the collider on the seccond staircase would cause up to be the default direction when there is a choice - like in floor 2 of your image.
Can you post a your code that isn't working?
That is my code ignore the polyCollider it's disabling something else. But I'll try what you suggested
using UnityEngine; using System.Collections;
public class One_Way : $$anonymous$$onoBehaviour {
public entered = false;
public BoxCollider2D player;
public BoxCollider2D ignore1;
public CircleCollider2D ignore2;
EdgeCollider2D edgeCollider;
PolygonCollider2D polyCollider;
void Start(){
polyCollider = GetComponent<PolygonCollider2D>();
edgeCollider = GetComponentInParent<EdgeCollider2D>();
}
void Update(){
Physics2D.IgnoreCollision(ignore1, ignore2);
Debug.Log (entered);
if(entered){
polyCollider.enabled = false;
edgeCollider.enabled = false;
}else{
polyCollider.enabled = true;
edgeCollider.enabled = true;
}
}
void OnTriggerStay2D(Collider2D player){
Debug.Log(entered);
entered = true;
}
void OnTriggerExit2D(Collider2D player){
Debug.Log(entered);
entered = false;
}
}
Glancing (and not thinking too hard) at your code, if you are applying this to a staircase, you need to enable by entering zone at the bottom, disable when exiting - UNLESS - you are touching stairs collider, in which case you disable at top of stairs. Inverse for going down...
I know it's been a while but I have an issue, entering one collider and it enables all the colliders including the ones for the second staircase.
ensure you are using prefab instances (not sure how, but the other day I managed to be dynamically editing the prefab in game, causing all 'non'-instances of it to have the same values etc.)
are you using 3 collision fields per staircase? one to be the stairs one at either end to toggle the stairs - note, i wouldnt place these on the staircase, but slightly away from it so as to not be triggered while on the staircase.
zone2/zone1
Your answer
Follow this Question
Related Questions
How to get the center of a collider face and the halfExtents to the corners of that face? 0 Answers
Internal collisions 1 Answer
Is it possible to automatically create and attach a collider to an object whose edge is detected 0 Answers
Character Controller slowing down after climbing a slope 1 Answer