Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. 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
  6. 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:
    64


    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:
    64
    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.     }