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):
https://drive.google.com/file/d/11-lGs32zYh4FkaEWs0giiTfBVSt52xSt/view?usp=sharing

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:
https://drive.google.com/file/d/1iML--kcTa-7Sw9Rm8AV1Stfr1DHdQr91/view?usp=sharing

project link : https://drive.google.com/file/d/1wZiBxL07yib1M8XbHXDRCS4-2P-1PWQ_/view?usp=sharing
Additional project images :
https://drive.google.com/file/d/1aEms8vho89Yq3Jvzm1dVXFmZotl9YmJD/view?usp=sharing
https://drive.google.com/file/d/1MNVNcgyWI4M0bxC3hkXTEUmIRIgLnw72/view?usp=sharing
https://drive.google.com/file/d/1diXqkrEo2A1eZe_vxOU-U-FcEdKgvBX7/view?usp=sharing

: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