Input Manager to rule them all

Hey DK… remember long ago, when I was bitching about the new camera.inputs system, and I was sort-of talking about a controller “patch panel” (and “ganging”, “binding”, and/or cascading controller events)?

And remember when I suggested… that all inputs should pass to a new kind of ActionManager… made for controller inputs… but uses same trigger/action registering system as current actionManagers? Remember?

Boy, was I ever off-base, just like the entire contents of this post, huh? heh. But still, doesn’t this sort-of “feel” like an actionManager made for controllers/inputs?

EventManager, InputManager, ObserverManager, ActionManager, a triggers and actions festival. :slight_smile:

Maybe it’s just me. All in all, ignore this, not pertinent. Sorry for interrupt.

1 Like

No worries:) I do remember but at that time I did not get the point (Now I do :))

Please let me know what you think of the API

1 Like

So really, it depends on whether BabylonJS is aiming at being a game engine that targets multiple platforms or more towards being a 3d framework that targets traditional HTML5 platforms.

A web developer won’t have many use cases for an input mapping system I guess …? while a game developer may want to target multiple platforms, and multiple input devices, or manage input for multiple game states (menu, multiplayer, story mode), multiple gameplay states or multiple vehicles (i.e. tank, planes, walk). In such a scenarii, the use cases increase in numbers.

Hence it really depends on whether you see BabylonJS as a game engine or a 3d framework.

If you go down this road, the big names can serve as inspiration for the implementation.

In Unreal:

In Unity:
image
However, for unity, I would advice having a look at the plug-in ReWired in the asset store, which is more robust and flexible than the unity input manager ^^

In Godot Engine:

Hope that helps :slight_smile: happy to see that the discussion is getting fed with more voices and ideas :smiley:

PS: I have a more serious read through the thread tomorrow :slight_smile:

2 Likes

You can kinda script all this with how the system is. I mean its not as easy as a cool UI with drop down visuals, but for the most part if you code up a Controller object and just change what your inputs are depending on the client you can handle almost any case I would imagine.

Agree with @Pryme8!

So the question is: does what you see in my branch suit the underlying need

Now with mouse:

    hub.addEvent(`Yeah`, [
        { device: BABYLON.InputHubDevice.Keyboard, keyCode: 13, altModifier: true },
        { device: BABYLON.InputHubDevice.Keyboard, keyCode: 32, shiftModifier: true, rightModifier: true },
        { device: BABYLON.InputHubDevice.Keyboard, keyCode: 82, released: true },
        { device: BABYLON.InputHubDevice.Mouse, button: 0, released: true, shiftModifier: true, rightModifier: true },
    ]);

    hub.onEventObservable.add(evt => {
        if (evt === "Yeah") {
            foo();
        }
    })

    var foo = () => {
        console.log("yeah!")
    }
2 Likes

Looks nice, but why not using letters instead of keycode? Or maybe even better: an enum, so that the gamedev can use the autocompletion to find the key they are looking for.

Note: we need to make sure that the structure you are creating scale to continuous values, such as controller axis, pinch touch, controller’s left and right triggers, mouse position/dragging? Godot Engine uses the concept of action strength, hence all events return a number between 0 to 1. Discrete events can only return 0 or 1 while continuous event can use all the range. Also I believe that an axis can return -1 to 1? I need to read their doc.

Also, it would be nice that we can import the input map from a JSON file… So that we can edit it independently from the code.

You may need the concepts of players, layouts and categories as in ReWired, if you want to deal with multiple controllers (multiplayer games), multiple input layouts (e.g. left and right handed players, etc…) and importantly different gameplay contexts (e.g. in menu, in tank, in top-down view).

Concerning the touch input, it would be nice that the pinch input that you coded for the arc rotate camera become usable for anything else. I had to cancel the pinch zoom feature of my game cause I was using a free camera :smiley:

1 Like
  • String: How do you capture keys like space or numLock?
  • Enum: Not something I want to maintain for all the keyboards in the world :slight_smile:
  • Importing from a JSON file: Not something I want to do. It is client code.
  • Players, etc: I do not want to go to that level. This is user code again. Babylonjs is a framework and I do not want to bloat it with too high level and very specific features. We have the extensions repo for that
  • Continuous event: Yep good point. Based on my current API, how do you see the trigger declaration? Can you provide some examples so I can back track it?

String: BabylonJS (or HTML5?) is already using strings, try pressing space, insert, delete, page down here: https://www.babylonjs-playground.com/#XZ0TH6#22

Enum: I guess what I mean is some kind of dictionary, as in phaser (or other game engines): Phaser.KeyCode - 2.4.4 - Learn - Phaser

JSON file: yes but to save to/read from JSON could be facilitated if you develop the input manager with that in mind that gamedev will probably want to save their mapping into a file :smiley:

Players: I would say that you need to make sure that your solution scales to local multiplayers (i.e. several gamepads).

Continuous event: you may want to have a look at the section “ADDING ANALOG VALUES TO ACTIONS” here: Godot Engine - Introducing the new axis handling system. Does that help?

Wait I’m trying to help you guys here but I won’t do the job:)

I started a branch so you can contribute and shape the tool you need.

I checked your links and this seems all great (all but the enums as we should not considering maintaining an enum with all the keycode of the world. Just think about Chinese or Japanese Unicode values)

The branch is yours to play with. I’m personally fully booked on the node material editor:) (Creating the Babylon.js Node Material - Babylon.js - Medium)

3 Likes

I am not sure what to do with this link you gave us @Deltakosh:

If I understand, there is a branch input-manager :smiley: and we can try to implement something in that branch. Should we open the PR once we are done implementing it, or now?

Yep the idea is to start adding more behavior like the one you mentioned to that branch

You can do PR anytime you want and we can then discuss over code (which is easier)

Then when we are all happy with the shape of that new API we can merge it in master and makes it a new feature of 4.1 :slight_smile:

2 Likes

Yep, I mean, I am happy to contribute but right now my free time is hard to find :smiley: so maybe more for 4.2 ^^

I 100% agree on JSON and hooking the event.key attribute along with the keycode. Can we please replace the device: BABYLON.InputHubDevice.Keyboard with a string?
If you have looked at many good games, they allow players to map actions to their own gestures. This is what I want to have happen with this eventually. I would like to be able to export and import a JSON file.
Also, how easy is it to register and unregister event handlers? I’m thinking of the action “up” will need a different handler for the inventory screen vs the navigation screen.

As I said, I have other things to work on but I will gladly merge any PR done on that branch

This is a very good idea, especially if everything that @frastlin mentioned ends up being implemented eventually. Our project could throw out a lot of lines of client side code code if it could use this (and we have not even started with the mobile controls implementation for the main game yet!).

Can we also have a standard API to query the names of the keys that have been set? This is very kludgy in JavaScript at the moment with KeyboardEvent.keyCode being deprecated and KeyboardEvent.key being inconsistent across keyboard layouts. We use a manually coded lookup table ATM, but a standardized solution would be welcome!

This is very interesting

Re: touch etc., I would want something like {event, key(W), screen(x1,y1,x2,y2,1finger), joy(‘up’), voiceaccessible(“walk forward”)}
With observables (isHeld?, hasbeenTapped? [A queue]) Or some such… The joystick camera is a pretty exemplary example of touch input.

Like implementation is hyper specific but cross compatibility is choice
Open web standards after all

I am late to the party on this but this would be a very welcome addition to the Babylon js Editor

Maybe useful for later, there seems to be some progress about HTML5 and gamepad support here: Gamepad

I could not find a HTML5 input manager though…

Another note for later, the general controller in Playcanvas: pc.Controller | PlayCanvas API Reference