Tips for managing the three.js player mesh (md2) while incorporating cannon.js physics

Check out a cool demo

I recently made the switch to using three.js (coming from a background in OpenGL and C++, so adapting to JavaScript wasn't too difficult). To get a better understanding of how to set things up, I explored various three.js examples. I came across this helpful video [xttp://www.youtube.com/watch?v=1ENVYLp_NgY] explaining how to integrate cannon.js, and I thought I'd give it a try as well :)

My ultimate goal is to create a 3D world with shadows, physics, and an animated player that can interact with objects. I decided to start with this example [xttp://threejs.org/examples/webgl_morphtargets_md2_control.html] because it already had the animated player mesh and the player controls were suitable. I also added OrbitControls to allow the camera to look around.

Everything seems to be working smoothly, except when I attempt to connect the player mesh to an object in the physics world (for the player to repel/push stone blocks). To keep things simple, I tried linking the player mesh to a basic sphere shape. However, when I try updating the object's coordinates to follow the player mesh's movements, the player animates but doesn't move (I've commented out those lines in the update() function).

      /**
       * Issue: Preventing player from moving :(
       **/
      player.position.copy( playerMesh.root.position );
      player.quaternion.copy( playerMesh.root.quaternion );
      player.velocity.copy( new THREE.Vector3() );

There's also a "gyro" aspect in the md2 player mesh object that seems to adjust the light position to coordinate with the player's movement, but I'm not fully grasping how it works (the gyroscope component is a bit confusing, and I'm not sure if it's causing the issue).

You can find the code repository on GitHub

UPDATE: Issue resolved, check out the commit on GitHub :)

Answer №1

Successfully made and pushed the correction: here (I had to stabilize the sphere by updating the position using x, y & z floats instead of using the vector3.copy method). It may not be the conventional way to implement this but it gets the job done for now.

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 successful loading of tab favicons in the DOM of an angular chrome extension is a triumph, however, explicit XHR requests are unfortunately

I've been immersed in developing a Chrome extension with Angular 5. Successfully, I managed to extract favIconUrls from the tabs API and link them to my popup.html's DOM. The icons are retrieved and displayed without any hiccups. See an example ...

How can I use jQuery to check a checkbox without triggering its bound event?

I've created a custom checkbox that will log its value to the console, and I'm trying to add a button that can tick the checkbox without triggering the checkbox event. This is purely for educational purposes. $(document).on('click', ...

AngularJs Controller with explicit inline annotation

I usually inject dependencies using inline annotations like this angular.module('app') .controller('SampleController',['$scope','ngDependacy',sampleController]); function sampleController($scope,ngDependacy) { ...

Swapping out video files with varying quality using HTML5 and Jquery

Objective: Implementing a feature to change the video being played when a user clicks a button using Jquery. Example website for reference: (click on the "hd" button in the player control) More details: When the page loads, the browser will play the fi ...

Is it possible for Vue to retrieve refs on mounted during nextTick following the dynamic import of the component?

Utilizing Nuxt js and Element UI, I have dynamically imported Element UI plugins in the plugins folder. export default () => { Vue.component("ElForm", () => import("element-ui/lib/form")); Vue.component("ElFormItem", ...

Clearing LocalStorage and Cache upon initial loading in Next.js

Our project requires continuous updates, and currently users are required to manually clear their cache and localStorage data after each update in order to access the new features. Is there a solution to automatically clear all cached data upon user visi ...

Tips on incorporating a fresh item into a expansive tree view using a recurring function or action - specifically geared towards the MUI React JS Tree View component

I am looking to implement a function or action that allows for the dynamic addition of new items to a tree view in MUI. The goal is to be able to click on a tree item and have it add another item, repeating this process as needed. <TreeView ...

Unable to transfer a function to a component using <Route /> tag

In the Erm component, the function setErm is undefined even though it is received by the App component. When passing something like something='foo', the ERM component receives it but not setErm={props.setErm} const App = props => { console. ...

Issue with Material UI select element not updating in onChange event of a dynamic form

Currently, I am developing a dynamic form that requires loading extra fields through JSON. However, I am facing a problem as the <Select> and <Radio> elements are not re-rendering after the value is changed. The form itself is a functional comp ...

Updating votes on the client side in WebForms can be achieved by following these steps

I am currently working on implementing a voting system similar to Stack Overflow's. Each item has a vote button next to it, and I have it functioning server side causing a delay in reloading the data. Here is the current flow: Clicking the vote butt ...

Tips for modifying the Collada color in threejs by utilizing a button

I have a project where I am trying to create a skeleton model with interactive bones. The goal is that when a specific button is clicked, a part of the skeleton will change color. However, I encountered an issue when I attempted to place two identical mo ...

Changes made to one order's information can impact the information of another order

Currently, I am in the process of developing a unique shopping cart feature where users input a number and a corresponding product is added to a display list. Users have the ability to adjust both the price and quantity of the products, with the total pric ...

Customize Vue.js: Disable Attribute Quote Removal for Individual Pages

We have a requirement to turn off the minify.removeAttributeQuotes property for certain pages. This is the content of my vue.config.js: const packageJson = require('./package.json') module.exports = { assetsDir: packageJson.name + &apos ...

What is causing the .responseToString function to be recognized as not a function?

Consider the following scenario with Typescript: interface IResponse { responseToString(): string; } export default IResponse; We have two classes that implement this interface, namely RestResponse and HTMLResponse: import IResponse from "./IRespo ...

Tips for extracting the image URL from my JSON string

I am in possession of a json file that includes URLs for images, and I have come across something that seems to be a URL, which is encoded as: iVBORw0KGgoAAAANSUhEUgAAADYAAAAzCAMAAADrVgtcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6m ...

Obtaining the value of a specific dynamic `<td>` element using jQuery

My page layout resembles this design (I am unable to post an image due to insufficient points, so I have it hosted elsewhere) My goal is for jQuery to identify the specific email when a user clicks on the delete button. For instance, if a user clicks on & ...

Testing React Hook Form always returns false for the "isValid" property

When creating a registration modal screen, I encountered an issue with the isValid value when submitting the form. In my local environment (launched by npm start), the isValid value functions correctly without any issues. However, during unit testing us ...

Utilizing PHP and jQuery Ajax in conjunction with infinite scroll functionality to enhance filtering capabilities

I have implemented infinite-ajax-scroll in my PHP Laravel project. This project displays a long list of divs and instead of using pagination, I opted to show all results on the same page by allowing users to scroll down. The filtering functionality works s ...

Creating JavaScript functions that accept three inputs and perform an operation on them

Apologies in advance if there are any silly mistakes as I am new to Javascript. I want to add "salary", "pension", and "other" together, then display the result in an input field when a button is clicked. Not sure if I have used the correct tags in my cod ...

What is the importance of including parentheses when passing a function to a directive?

Hello, I'm currently a beginner in Angular and I am experimenting with directives. Here is the code snippet that I am using: HTML <div ng-app="scopetest" ng-controller="controller"> <div phone action="callhome()"> </div> </div ...