What's the best way to grab information from a listener and get it in a game engine?

[Lance] What is the best way to grab information from a listener and get it in the game engine? We are currently trying to do Spasaki after my mouse. I made MouseControls.js that listens for mouse movement and records the X and Y of the cursor. Then I used the following code in the client engine to get it in the game engine

this.sendInput('mouseMove', {
 cursorX: this.mouseControls.cursorPos.cursorX, 
 cursorY: this.mouseControls.cursorPos.cursorY
});

      

then in the game engine I tried to read the second parameter in the processinput method like:

inputData.inputOptions.cursorY

      

but I am getting the error "Cannot read property 'cursorY' from undefined". I get that every key for other controls does the same thing every time, but I don't know how to pass variable information around (cursorX / Y). This is all a modification of the spaaace tutorial. Should I be making a mouse object instead?

UPDATE: I dug in and found out a little more, so I guess I narrowed down my problem. It looks like this:

At the moment the game engine handles inputs, it only has the input name with no additional information, which is great for keystrokes that do the same every time. However, with the movement of the mouse, as soon as I get the "mouseMove" input, I also need to get the mouse position and X from my mouse controller, which is not visible from the game engine (as far as I can tell). So how do I get these values ​​at this point?

Since you can't see my code, this is the equivalent of getting the "activeInput.up" value from KeyboardControls from the GameEngine's processing method

+3


source to share


1 answer


You are very close! :)

If you are sending input like this from ClientEngine

:

document.addEventListener('mousemove', (e)=>{
    this.sendInput('mousePos', { x: e.clientX, y: e.clientY });
})

      



then in GameEngine

you can access it via the options property:

processInput(inputData, playerId) {
    super.processInput(inputData, playerId);
    console.log(inputData.options.x, inputData.options.y);
}

      

Link: Lance docs

+2


source







All Articles