Search Unity

[C#] Using both touch to move & virtual joystick. A bit confused when to use what?

Discussion in 'Scripting' started by lkarus, May 28, 2015.

  1. lkarus

    lkarus

    Joined:
    Feb 25, 2015
    Posts:
    51
    I'm currently trying to implement both touch to move (touching a point on the level, and the character will move to that point, assuming that it is a walkable area) and also have a virtual joystick on an android app.

    The virtual joystick will not be visible. And when the user touches a part on the screen, if the user holds down his / her finger for a long time (maybe 0.3s) then I will render the virtual joystick that the user can use to move the character. And if the user quickly touches and removes his / her finger at a random location, this time the program will not render the virtual joystick but just move the character to that location.

    Currently I am thinking off having a timer that gets the start time of when the user has first touched the screen. Then I will be doing a check to see whether the user has lifted their fingers in x seconds, if not, render the virtual joystick. If yes, then I'll just move the character to that location. Do you think this is a good approach? I'm new to input related stuff so I'm not really sure if this is the best way to do things.
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
    Yes, this sounds perfectly reasonable.
     
  3. lkarus

    lkarus

    Joined:
    Feb 25, 2015
    Posts:
    51
    Thank you steego!