Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tyxman · Jun 30, 2015 at 11:53 PM · collideredge detectionstairs

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 directalt textion.

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)

screenshot-1.png (253.5 kB)
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Myth · Jun 30, 2015 at 11:58 PM 0
Share

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?

avatar image tyxman · Jul 01, 2015 at 12:00 AM 0
Share

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;
     }
 }
avatar image Myth · Jul 01, 2015 at 10:08 PM 0
Share

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...

avatar image tyxman · Jul 15, 2015 at 03:36 AM 0
Share

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.

avatar image Myth · Jul 23, 2015 at 01:11 PM 0
Share

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

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

I can't make my character walk up stairs or slopes using the following code and rigidbody. Can someone help? 2 Answers

Character Controller slowing down after climbing a slope 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges