Simple Virtual Joy Stick using Lua?

Is it possible?..i need it on my next game… do you have an idea on how to do it?..and if anyone here already made one before,…can you teach me or give some example as my guide?..thanks!

I would try by defining a touch region, with a center origin. Then you can translate touch X and Y from the origin, and use that value as “joystick” input.

Edit: what @britzl said. :joy:

3 Likes

Yes, it’s possible to create a virtual joystick, but you need to implement it yourself, unless someone else already has created one. A virtual joystick should be fairly easy to implement. Some ideas:

  • Create it as a gui or go
  • Use on-screen controls graphics from Kenney (http://kenney.nl/assets/onscreen-controls)
  • Acquire input
  • In on_input() detect pressed state, keep track of pressed position
  • In on_input() detect released state
  • In on_input() detect changes in action.x and action.y and calculate the diff between pressed position and vmath.vector3(action.x, action.y, 0). Normalize the diff in some way to get a value between -1.0 and 1.0 per axis.
  • Use the diff to move your player character or some other thing in your game
4 Likes

i like your idea…ill give it a try later…thanks! :’)

thank you very much sir for sharing this idea to me!.. :’)

if i cannot do it,…maybe i will do the simpler one (4 or 6 directional arrows)…and maybe that’s my last resort… :’)

I’m making an example for this, on screen buttons, for the Defold book.

Edit:

Updated and reusable version here:

9 Likes

@britzl wow!..its great!..thanks for sharing this!..

1 Like