I want to use an virtual joystick to send out an input in the input manager

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rabbitnap

I have made an virtual joystick. Now I want ist to be registered when you move it in a direction. For example when I move it to the right side I want it to be registered as an right arrow key press just as it us handled with a real joystick in the input manager

Is this possible?

:bust_in_silhouette: Reply From: Mark Lisicic

It is possible. I personally followed this video to make the joystick and then edited the function to translate the offset of the front sprite in relation to back sprite to a simple Vector2 (so for example, (0,1) is right and (-1,1) is up and right). From there it’s just a matter of a function to react to these values in realtime and press and release the buttons (with Input.action_press() and Input.action_release())

I know it sounds quite confusing so here is my joystick.gd script and a picture of nodes placement.

Nodes tree
(Front sprite is the circular one that moves, and the Back sprite is the static one)

I have this saved as a custom scene so I can drop it in wherever I need a virtual joystick. And here’s a gif to see the result.

If it’s still unclear or if you want me to clarify something just ask.

Thanks man, I couldn’t find a way to press a button true code. You helped me a lot.

Rabbitnap | 2020-07-19 21:43

Hey bud, i have a weird problem. My joystick just wont move at all when ever i put it in the main game scene. So i tried to uses yours… and got the same problem it just won’t move. Do you have any clue why it isn’t moving?

Example Video: Gofile - Your all-in-one storage solution
Example Video

Rabbitnap | 2020-07-20 08:37

I have no clue, maybe I could help if I saw the project files.

Mark Lisicic | 2020-07-21 01:14