"Hey game devs! I am creating such a top down 2d game that have two or more character’s movement controls
(Say , Joystick , Mouse , Keyboard)
I have script for them but the main problem I face is that how will I make them changed using 3 toggle Buttons specifically designed for each type of movement. In short how will I make a whole script be controlled through Toggle buttons e.g If I turn on Mouse then all other Script parts ( Joystick and keyboard ) will automatically be turned off until the button it turned off so that I can give users variety of Player Controler."
The “Godot” way of doing this is to accept all three types of input at once, so hypothetically your player could be using a gamepad stick for movement but the keyboard for buttons. Unless you’re worried about mischievous brothers/sisters, this usually works fine.
If you do want to specifically set the mode, @zoern’s state machine idea would work fine:
enum InputMode { gamepad, mouse, keyboard }
var CurrentInputMode: InputMode = InputMode.gamepad
#[...]
func _process(delta: float) -> void:
#[...]
match CurrentInputMode:
InputMode.gamepad:
# do gamepad stuff
InputMode.mouse:
# do mouse stuff
InputMode.keyboard:
# do keyboard stuff
func switch_to_mouse() -> void:
CurrentInputMode = InputMode.mouse
#[...]
A lot of the rest would just be setting up your input map.
Specifically there is a chapter about “Implementing a Finite State Machine with nodes”.
State machines are really useful. Implementing one for yourself is a good learning experience that you’ll reuse later