-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve setting inputs for local multiplayer games #3555
Comments
I agree that something like this should be implemented in core, or we simply need a better interface. If you'd like to see an alternative approach of solving this problem, you may want to look at my own two-year-old proposal #104. My main use case is being able to split inputs down to multiple characters, but #104 could be extended to deal with several player input as well. For your particular proposal, the workaround is described by reduz, see #639 (comment), unfortunately the proposed solution is seen to be too complex to be implemented in core. |
As a workaround you can do something like: func get_input_action(original: String) -> String:
return original + str(player)
func _process():
if Input.is_action_pressed(get_input_action("jump")):
jump()
if Input.is_action_pressed(get_input_action("punch")):
punch()
if Input.is_action_pressed(get_input_action("move_left")):
move(left) You'll still need to add the input actions manually or with |
Or even simpler: func is_action_pressed(action):
return Input.is_action_pressed(str(player, action))
func _process():
if is_action_pressed("jump"):
jump()
if is_action_pressed("punch"):
punch()
if is_action_pressed("move_left"):
move(left) The worst part of setting up local multiplayer is defining all the new actions. Last time I was doing it I didn't even bother with the InputMap editor, I just manually copied player 1 in |
Well thats a shame, sure wish I would have seen that before writing the whole wall of text.
I admit, these are some fine workarounds to my problem, but even then, you both still had to add actions manually. So, how about just adding the ability to duplicate actions/inputs? You know, select on one or multiple actions/inputs, then press right click and select "duplicate" or press Ctrl + D like in the editor, and it makes a duplicate of the action/inputs and renames it (if you were duplicating |
Related to #1249. See godotengine/godot#29989 where something similar was implemented. However, it wasn't merged as no consensus was reached on the feature itself. |
what about something like
|
Just throwing my opinion in here. I have created a The Here is the latest source if anyone is interested: https://github.com/kuma-gee/explosive-delivery/blob/master/src/input/PlayerInput.gd |
I would like to make a smash bros like ui in which each player can have a mouse cursor controlled by the gamepad/keyboard/mouse/touch which can react to the ui |
This is being tracked in #4295. |
Maybe add the possibility to change player filter from default when running |
An enhancement to this would be awesome.@Braveo's suggestion seems awesome (but I am no expert). To add even more complexity (:sweat_smile: ) some thoughts that I had during my game:
Simpler implementation than presets?
|
If this is done ui controls need to take use of this system. |
what about this solution? |
Describe the project you are working on
1v1 fighting game, similar to Street Fighter or Mortal Kombat (This one specifically)
Describe the problem or limitation you are having in your project
(First time making an issue here, feel free to ask if something isn't clear)
As I was making my game, I noticed that setting up inputs for multiplayer was tedious and had many points of possible failure.
I started out by making the controls work for one player, which was quite simple. Just make some input actions, for example "move_left", "jump" and "punch", set fitting keyboard- and controller inputs for them, make a new scene named "Player" with KinematicBody as root and attach a script that looked something like this:
But wait, I need to make this work for 2 players! For that to work, I have to make whole new input actions, like "move_left2", "jump2" and "punch2" with their own keyboard- and controller inputs. I didn't want to repeat myself by making a separate scene for player 2, as both players should have the same abilities, so I edited the existing Player-scenes script to something like this:
With this code, I can have another player by instancing the scene and setting
player
to2
.Now, let's say that I wanted to add a new action, "move_right" for example. I would have to add it once per player on the input map, make a new variable, write it once per player again in the
_ready()
function and writeif Input.is_action_pressed(move_right)
, where I actually needed it. If I misspell the name anywhere during this process, which I sometimes did, it will not work. The editor throws an error when this happens, but I wish I could avoid this issue entirely.
Adding new players isn't any easy, either. If I wanted a third player, I would have to make new actions like "move_left3", "jump3" etc. and set new inputs for each one, again, and add them all in the
_ready()
function, again.Also, I hate that I have to add in new controller inputs for each player, despite the button on the controller being the same. It's not like I want player 1's "punch" be on the A button and player 2's on R1 or something.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
If I could just edit the actions once in the input map and then once in the code where I need it, just like when I made it work for one player, it would make my life a lot easier.
My solution would be "Input Groups". They are like physics layers, but for actions' inputs. For example, for the "jump" action, one could set the A button on controller 1 to be in Input Group 1 and the A button on controller 2 to be in Input Group 2. Now, when the A button on controller 2 is pressed, it would say something like "The "jump" action on group 2 was triggered".
See also issue #2273 for something similar with "Action Sets".
Additionally, I would appreciate if I could duplicate inputs. That would make setting controller inputs easier, as then I would only have to change what controller the input is coming from.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I'll add drawings to describe how I would change input map later. But imagine that next to an input, there would be buttons similar to the physics layer ones, and with that you could choose which Input Group the input is a part of. By default, a new input is part of the first group.
Input.is_action_pressed(action)
and similar functions would become something likeInput.is_action_pressed(action, group)
where thegroup
is the Input Group as anint
. If left unchanged, it will default to the first group (so if one is making a single-player game, they wouldn't have to worry about groups).With my solution, all I would have to do to add multiplayer is to change the initial Player-scene code to this:
And just like previously, I can instance the scene this code is attached to and change the
player
variable to set which player controls the instance, except it's much simpler!What If I want to add another action, like "move_right"? I would add only one "move_right" action in the input map, add in the inputs for player 1 and 2, put them into appropriate input groups and then add something like this to the
_process()
function:What if I want to add another player? I'll just add inputs to existing actions and put them into a new group (group 3 for example), and then instance the scene and set
player
to3
.If this enhancement will not be used often, can it be worked around with a few lines of script?
I worked around this the way I wrote on the "Describe your problem" section, but as I mentioned, it's tedious, I end up repeating myself a lot, and it will be easy to make errors.
Is there a reason why this should be core and not an add-on in the asset library?
I'm not an expert, but I don't think that add-ons can add the "Input Groups" feature, and certainly not duplicating inputs.
The text was updated successfully, but these errors were encountered: