how to convert keyboard controls (up, down, right, left) to => button controls

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

hello, jou wanted to create 2 different types of controls to control “kinematic body 3d”
here is control 1 (up down left right):

I would like to insert a 2nd control for the touch screen with 4 buttons (up down left right) but I don’t know how to do it, I don’t know anything about buttons, their possibilities on the screen are like this:

project link :
Additional project images :

:bust_in_silhouette: Reply From: jtarallo

Hi, so you’d need to add the buttons and lets say they are $Button_UP, $Button_DOWN, etc.

First of all, I recommend you move all that logic to a

func _input(event):

If not, you’re checking for input in every iteration of that sprite when you shouldn’t be.
So just copy and paste all the content of your _physics_process function but the move_and_slide(velocity) line and the rotate_z lines.

Then add to every condition needed, the $Button_(DIRECTION).pressed condition to check if the button is being pressed. So the first condition you have would look like this:

if (Input.is_action_pressed("ui_right") or $Button_RIGHT.pressed) and (Input.is_action_pressed("ui_left") or $Button_LEFT.pressed):
    velocity.x .....

Hope it helps. If you need further clarification, let me know.

thank you very much, you saved me a lot of time.

neutrino2020 | 2020-06-10 11:30