This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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?

in Engine by (44 points)

1 Answer

+1 vote

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.actionpress() and Input.actionrelease())

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.

by (20 points)

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

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: https://gofile.io/d/mZh45h
Example Video

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.