What is the most effective method for obtaining data from a user and transmitting it to the game's processing system?

[Lance] Seeking the most effective way to extract information from a listener and transfer it to the game engine. Currently working on making the Spaceship follow my mouse movements. I have created a MouseControls.js file that listens for mouse movement and records both the X and Y coordinates of the cursor. In order to send this information to the game engine, I utilized the following code:

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

When attempting to read the second parameter in the processinput method within the game engine:

inputData.inputOptions.cursorY

I encountered an error stating "Cannot read property 'cursorY' of undefined." While other control keys function consistently every time, I am struggling to pass variable information (such as cursorX/Y) around effectively. These modifications are being made to the Spaaace tutorial. Should I consider creating a mouse object instead?

UPDATE: After delving deeper into the issue and gaining more insight, I believe I have pinpointed the root cause of my problem:

At the point when the game engine processes inputs, it only receives the input name without any additional information. This setup works well for key presses that trigger consistent actions each time. However, with mouse movement, upon receiving the "mouseMove" input, I also need to access the mouse's X and Y position from my Mouse Controller, which seems to be inaccessible from the game engine perspective. How can I retrieve these values at that specific moment?

Given that you cannot view my code directly, this situation is akin to extracting the "activeInput.up" value from KeyboardControls within the GameEngine's processinput method.

Answer №1

Great job, you're almost there! :)

If you provide input in this way using the ClientEngine:

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

then within the GameEngine, you can retrieve it from the options property:

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

For more information, check out the Lance documentation

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The React Router fails to redirect to the correct page, instead leading to an empty page without any errors displayed

The React Router "Link" feature isn't functioning properly at the moment. Imagine we start at: "localhost:3000/api/pages". Upon clicking the dropdown item, the link becomes: "localhost:3000/api/pages/api/pages/abc". It should actually be: "localhos ...

Guide to updating user input on the screen when a click event occurs using Javascript and HTML

I've been working on writing HTML and JavaScript code that enables user input to change based on which button the user clicks. The idea is that the user enters find/replace values, and when they hit the replace button, the text they initially entered ...

The issue is that dates submitted from jQuery are not being captured in the POST variable in

I'm currently in the process of integrating fullcalendar into my php application. However, I've encountered an issue when trying to save events to the database - specifically, the database only accepts title and url if they are enclosed in doubl ...

Is it possible to retrieve a specific object using PDO fetch method?

I am currently working on a page that connects to a database using PDO and prepares SQL_CALC_FOUND_ROWS for pagination. Everything is functioning well. However, I want each result to display a text popup when clicked. This is where I need to target a speci ...

What is the reason behind functions not requiring (args) when called with parameters?

Have you ever noticed the difference in behavior between these two code snippets? var foo = document.getElementById("foo"); foo.addEventListener("keydown", foo); function foo(e){ console.log(e.keyCode); } And this one: var foo = docum ...

Switching Json to Typescript

I have a file named items.ts with the following interface: export interface item{ Name: string; IsSystemItem: string; ConfiguredSegments: ConfiguredSegments; } export interface ConfiguredSegments { LiveA: LiveA; } export interface LiveA { Weig ...

Numerous Cycles Stemming from a Single Answer

My goal is to display a list of products with their details, including a sublist of product models that are checked in the detailed list. The challenge is to achieve this using only one GET request. This means retrieving the JSON data of products once and ...

jsGrid is failing to load within a Vue application that is utilizing static data

Struggling to implement jsGrid for a basic table with header sorting in my Javascript and Vue application. Having trouble loading the sample code with various components spread across different files. Here are the relevant parts: HTML (symbol-container is ...

Experiencing difficulties with the hamburger menu dropdown not displaying

Currently, I'm working on creating a mobile collapsible navigation bar. When the screen size is reduced, the items in the navbar disappear and are replaced by a hamburger button with a dropdown menu containing the previously hidden items. I've be ...

Looking for a way to limit the number of characters allowed per line in a textarea using jQuery

I have the following HTML textarea: <textarea name="splitRepComments" cols="20" rows="3" ></textarea> I have implemented a maxlength restriction using jQuery with the following function: var max = 100; $('#splitRepComments').bind(" ...

Activate CSS Animation with a Click using JavaScript

I'm trying to create a simple hamburger icon that triggers a CSS animation on click using pure Javascript (no jQuery). Currently, I have the animation working when adding a class to the hamburger icon, but when I remove the class, the animation abrupt ...

Find the item in the pop-up window

When removing a user from my list, a JavaScript popup pops up prompting to confirm the action with two buttons "OK" / "Annuler" : https://i.sstatic.net/BEdH2.png Is there a way to use Selenium to find and interact with these buttons? ...

Visualization of geometrical shapes in Three.js using Json formatting

I am seeking help with displaying the wireframe of a parallelepiped defined by vertexes in Json format using Three.js code. Here is the code snippet I am working with: var testCube ={ "metadata":{ "version":json['versi ...

Window.open function failing to function in Internet Explorer even when prompted by the user

Similar Inquiry: Issue with 'window.open()' function in IE8 - Error Message: Invalid argument. Take a look at this page: http://jsfiddle.net/S7Crc/ It is evident that when "click me" is clicked, a window opens correctly in Firefox but not i ...

Issues with state persistence in react-draggable

I've been trying to save the state after refreshing the page by creating a handling function. However, it seems like the state is not saving. What can I do to fix this issue? const DraggedItem = () => { const [x, setX] = useState(0); const [y, set ...

Implementing the ui-tinymce Directive Within a Different Directive

I am attempting to implement the ui-tinymce directive within another directive: angular.module("risevision.widget.common.font-setting", ["ui.tinymce"]) .directive("fontSetting", ["$templateCache", function ($templateCache) { return { restrict: ...

Tips for effectively utilizing FnFilter() to achieve precise matches in a multiselect scenario

Is there a way to pass multiple values in FnFilter() and ensure an exact match? I have been using "fnFilter" with the following syntax - fnFilter("^"+searchString+"$", 18, true, false); and I set "bsmart:false" My values include 10, 100,101,102, 1000 an ...

Create a new button dynamically within an HTML table row using pure JavaScript programming techniques

Currently, I am retrieving JSON data from an API and then displaying this data in an HTML table using plain JavaScript. My goal is to dynamically add a button at the end of each row for additional functionality, but so far, I have been unable to figure out ...

How can I link a Vue.js webpage with a WordPress site?

Looking to integrate a Vue.js 2 single page into an existing WordPress website? Perhaps you've already got an old WordPress site and now want to develop a new Vue tool or page that can be added seamlessly to the menu. How can this be achieved within W ...

Error: Unable to assign the 'schedule' property to a null value

I'm currently developing a scheduling application using React.js and have implemented a draggable scheduling feature for users to indicate their availability. Everything seems to be working smoothly, except for one pesky error message: TypeError: Cann ...