Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2D Vertical Scroller Limit Player Movement to Left or Right Only

Discussion in '2D' started by kingjavo, Jul 12, 2015.

  1. kingjavo

    kingjavo

    Joined:
    Feb 3, 2014
    Posts:
    17
    I'm working on a vertical scroller and I need the player to only rotate left for with without going backwards so 90 degrees left or right max.

    Anyone know the best way to accomplish this? It's for mobile devices as well so touch and drag is the movement I'm after.

    Thanks in advance! :)
     
  2. geek_freek

    geek_freek

    Joined:
    Aug 26, 2014
    Posts:
    51
    can you illustrate or provide some example as to what you're trying to accomplish.
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Try mathf.clamp to have a min & max value for the rotation value.
     
  4. kingjavo

    kingjavo

    Joined:
    Feb 3, 2014
    Posts:
    17
    Hi Guys,

    I could really use a little help if you have time. I've read and watched every tutorial Unity has and still can't seem to get the player movement working for my game. All I'm trying to do is make a 2D top down vertical runner game on mobile. I can get the player to move wherever I slide my finger, but the rotation is off and so is the left and right wall camera smoothness.

    I only want my player to rotate around 60 degrees left or right from the up facing mode as neutral. So when I slide left the player (top-down) rotates left up to 60 degrees. Same with right sliding. The boundaries on the left and right I like the camera to now shake or bounce once the player hits the wall.

    I've tried using all sorts of things from everything I've found, but the movement is not there.

    References...

    https://www.facebook.com/goalherosoccer

    https://www.facebook.com/touchdownherogame




     
  5. kingjavo

    kingjavo

    Joined:
    Feb 3, 2014
    Posts:
    17
    I'm pretty sure I tried that, but couldn't get it working right. I'll see if I can post some code soon to help show what I've tried.