|Topic was automatically imported from the old Question2Answer platform.
For a 3D game, I need a virtual joystick for touchscreen devices, and I want use it for control the translation of a
KinematicBody. I am using
GDScript for this game.
How I can do it?
Thanks in advanced.
You need a scene with a node that follows the touch position (a sprite maybe).
To simulate joy axes, get its position in the scene together with the width and height of the scene. You can use a Position2D node placed at the bottom right of the scene to find the height and width of the scene by calling $Position.get_position().
To get values ranging from -1 to 1 use:
-1 + (touch_x_position*2)/width and
-1 + (touch_y_position*2)/height (but remember +y is downwards so hopefully you will figure out how to flip the values)
All you need now is to listen for touch input events and get your virtual joystick axes values and use them like you use real joysticks.
I could write the whole script but that will take some time so I hope this is useful enough to give you an idea on how to go about it.
And how would you convert the vector2 to vector3 to move the player?
You use the y axis of the virtual joystick to control movement along the z axis(forward and backwards) and the x axis of the virtual joystick to control the movement in along the x axis(sideways). They should work just like a real joystick works.
magicalogic | 2023-01-16 16:16
Sorry I was asking How would i implement that using
move_and_slidebut I figured it out, thanks for replying.