Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Climbing 2D Stairs Problem

Discussion in 'Physics' started by 1ht1baron, May 13, 2018.

  1. 1ht1baron

    1ht1baron

    Joined:
    Aug 15, 2017
    Posts:
    65


    My player cannot climb this stairs. Firstly, i want player can climb steep wall. Also, when i stop in step, I do not want player to slide down. Please, help.
     
  2. Elveskevtar

    Elveskevtar

    Joined:
    May 16, 2018
    Posts:
    7
    I vaguely understand your question but you did not explain it well. If you want something of this nature, I believe your best bet is to check if the projected movement of the player is going to collide with a wall. If it is then check if this movement plus some verticalOffset (depending on how high you want your character to be able to climb) will still result in a collision. If it does, you shouldn't do anything and just let your player collide. If it doesn't, find where the vertical step is and move your player up to the step.
     
  3. 1ht1baron

    1ht1baron

    Joined:
    Aug 15, 2017
    Posts:
    65
    Thank you for reply. I solved the problem with FreezePositions.
    Code (CSharp):
    1.    
    2. private Rigidbody2D myRigidbody2D;
    3. void OnTriggerStay2D (Collider2D other)
    4.     {
    5.         if (other.CompareTag("Stairs")) {
    6.          
    7.             if (moveVelocity == 0) {
    8.                 myRigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation;
    9.  
    10.             } else {
    11.                 myRigidbody2D.constraints = RigidbodyConstraints2D.None;
    12.                 myRigidbody2D.constraints = RigidbodyConstraints2D.FreezeRotation;
    13.  
    14.             }        }
    15.     }