Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple 2D Joystick Help

Discussion in '2D' started by VFranklin, Oct 23, 2019.

  1. VFranklin

    VFranklin

    Joined:
    Jul 26, 2017
    Posts:
    48
    Hi,

    I want to be able to move my character around on a mobile platform.

    I want to have a simple kind of touch interaction where if the player taps the screen, the character has an upward vector applied (they jump) and if someone presses to the right of the character the character will slide right towards the location of the finger.

    How can I go about coding his?

    Any help greatly appreciated. Thank you!
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    906
    Hello VFranklin,
    I like to break down my coding problems into bite chunk pieces, which makes it a bit easier to figure out where to go next.
    You have two tasks you would like to complete,
    • Jump if the user taps
    • Move to the right, if the user presses to the right of the character
    For the first task, you can break this down into two parts
    • Tap input
    • Make the player jump

    For the second task, you have four parts
    • Touch down input
    • Convert the touch input position from screen space to world space
    • Check if the touch world space position is to the right of the player position
    • Move the player towards the right
    When you have broken down your tasks in these smaller pieces, it will be easier for you to search for ways of completing these tasks, and also to implement them.

    Good luck, and let us know how it goes!