Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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.     }