#How do I do top-down touch screen controls?
1 messages · Page 1 of 1 (latest)
Start with just keyboard controls. The mobile overlayed controls are trivial to implement. You just tell them to cause InputEventActions to happen.
But while you get to that, just bind them to keyboard keys or a joystick
The InputMap is controlled from Project>Settings>InputMap
That's fine, I guess. And how exactly do I code top-down controls with that?
Once you have the actions defined.
You can use Input.get_vector() to read their current status and transform them into a vector. Then you can just move the character with that vector.
The on-screen controls would later, when pressed, create InputEventAction objects and send them to the game window with Input.parse_action_event().
And they would work just as well with Input.get_vector()/Input.is_action_pressed()/etc as pressing the actual buttons bound to the actions.
I'll try and do everything you mentioned, but I'm a little confused still. Wouldn't linking the keyboard inputs to the vector make it more stiff and limited like with the keyboard?
I mean, I don't even know how to write things down on Godot and it's probably better to have an universal control rather than 2 different ones
Like I said I'm really really new to all this so I'll need a better explanation overall, like I really appreciate your effort but I'm just really slow
You just need to create the action.
What you bind to it doesn't matter, since you can also bind any amount of inputs to the same action (for example, i have a game where the "forward" action is triggered by SPACE, W, Up on a DPad and Up on the left stick)
Since you'll be using UI elements, the actions may as well have nothing bound to them, but you'd probably want to bind SOMETHING in the meantime.
The action is just what you'll query for reading inputs. But there's many ways to make that action fire.
Oh, I kinda understand now. Will see if the tutorials I found can do the trick for the keyboard controls in the meantime.
I've never really done mobile controls so idk which node is the best to start with.
But an Area2D can detect mouse inputs. So you could make a circular one and check where the input happened relative to its center.
Then move a sprite to the pressed location (for visual feedback) and create an InputActionEvent from the pressed position.
If the coordinate (relative to the center) was Vector2(10,50) and the circle is 100 in diameter.
Then you'd create and send the actions "down" with a strength of 0.1 and "right" with a strength of 0.5
(the strength of actions always range from 0 to 1)