0 votes

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 : https://drive.google.com/file/d/1wZiBxL07yib1M8XbHXDRCS4-2P-1PWQ_/view?usp=sharing
Additional project images :

in Engine by (22 points)

1 Answer

+1 vote

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.

by (380 points)

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

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.