How can I make visible button's to screen to make my Player move

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

Hi! How can I add visible button’s (or swipe to direction) to my playing screen/scene (left and right) and by pressing them my player moves. I already have arrow key controls added but if I wan’t to play my game on mobile devices so I need the screen touch buttons or swiping to the direction.

I think this is my code for moving:

var sideways: float = 0.0
if Input.is_action_pressed(“moveRight”) and is_on_floor():
sideways += 1.0
if Input.is_action_pressed(“moveLeft”) and is_on_floor():
sideways -= 1.0

Thank you! Kouvostoliitto

:bust_in_silhouette: Reply From: AbDevTM

Make a new scene.
Make the root node a canvas layer(This will be your UI).
Add a touchscreen button, give it a texture and position it where you want it to be. Make sure it’s positioned in the viewport.
Finally in the inspector tab, find the action property and write the input of your action.
E.g moveRight, moveLeft, Fire and so-so!

Thank you, I got that. Now I’m having another problem: responsibility. When I adjusted the touchscreen buttons to bottom corners, the left one is perfect but the right one is in the middle of the screen when I tested the game on my phone. How can I fix it to the right?

Kouvostoliitto | 2023-01-02 12:27