Search Unity

ignoring Horizontal inputs

Discussion in 'Scripting' started by fosmark13, Aug 27, 2015.

  1. fosmark13

    fosmark13

    Joined:
    Feb 16, 2015
    Posts:
    91
    hi i´ve been searching for a solid answer for what i want to do but i just can't find anything like what i´m trying to do. i have the character grabbing a wall (ninja gaiden style) so his movements are only in the Y axis, just up and down, but when i press any of the Horizontal axis he just go down... this is fine, so what im trying to do here is that when he is on the wall just ignore the Horizontal inputs, only when he is on the wall, basically do nothing when any of the horizontal buttons are pressed. Thank you
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    make boolean onWall. Then you can change it. Maybe with OnColliderEnter2D set it true, OnColliderExit2D set it false. And then:
    if (!onWall) {
    //here your moving on x-axe
    }
     
    fosmark13 likes this.
  3. fosmark13

    fosmark13

    Joined:
    Feb 16, 2015
    Posts:
    91
    that worked just fine, i actually had a bool called touchingWall, so i just have to put the X axis code inside an If that says: if (grounded && !touchingWall) then do the X axis so when he is touching wall he doesn't move anymore.