Skip to content

YAMIH ( Yet Another Multiplayer Input Handler ) is an attempt at creating a more modular approach to Godot's Input system, especially for local multiplayer games.

Notifications You must be signed in to change notification settings

MarageDev/YAMIH

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YAMIH

YAMIH ( Yet Another Multiplayer Input Handler ) is an attempt at creating a more modular approach to Godot's Input system, especially for local multiplayer games. It can handle keyboard inputs, controllers ( and probably also all the other inputs possible in Godot but I couldn't try the other ones ).

It can support at least 6 players ( tested ), but it can probably support even more players as long as you have enough unique inputs.

image

Presentation

Input

extends Resource
class_name C_ModularInput

@export var action_name:String
@export var input:InputEvent
  • action_name is used later in the InputManager to add this action ( once formatted ) to the designated InputMap.
  • input is used to specify which input you want to capture for this action ( key, joypad ... ).

PlayerInputHandler

extends Resource
class_name C_PlayerInputHandler

@export var PlayerIndex:int = 0
@export var PlayerName:String = "Player"
@export var Inputs: Array[C_ModularInput]
  • Inputs is used to store all the actions possible for this player.
  • PlayerIndex must be different for each players.

PlayerName has no real use besides the demo.

InputManager

extends Node
class_name C_InputManager

@export var Players:Array[C_PlayerInputHandler]
var Actions:Array[String]

func _ready():
	update_all_actions()

func write_actions_to_input_map(Player:C_PlayerInputHandler,InputMapRef:Object = InputMap):
	for InputRef in Player.Inputs:
		var formated_action_name:String = str(InputRef.action_name,"_",Player.PlayerIndex)
		InputMap.add_action(formated_action_name)
		InputMap.action_add_event(formated_action_name,InputRef.input)
		Actions.append(formated_action_name)

func update_all_actions():
	for i:C_PlayerInputHandler in Players:
		write_actions_to_input_map(i,InputMap)
  • Players stores all the players with their associated actions ( class of C_PlayerInputHandler, see above ).

  • write_actions_to_input_map adds every Inputs stored to the designated InputMapRef as [Action Name]_[Player Index].

  • update_all_actions is used if you plan to add/remove another player while playing.

Demo

Principle

It adds UI_PlayerCard.tscn for each registered players in the InputManager.tscn node referenced as an export, and display the action, name, player index on the according card. It's mainly here to verify that everything works correctly.

image

About

YAMIH ( Yet Another Multiplayer Input Handler ) is an attempt at creating a more modular approach to Godot's Input system, especially for local multiplayer games.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published