Events related to collisions in Physijs

Two boxes are at play in my scenario. One starts on the ground while the other is dropped on top of it, with gravity turned on. I'm attempting to trigger the collision event listener on the bottom box that rests on the ground, but for some reason, nothing is being logged as expected.

A new Physijs.BoxMesh object named 'c' is created using a CubeGeometry and MeshBasicMaterial, positioned at coordinates (10, 0,-5). A collision event listener is added to 'c', yet when a collision occurs, the expected message "hello world" is not printed out.

scene.add(c);

A clone of 'c', named 'p', is then created with its position set to a height of 50 units and added to the scene.

I'm stumped by what could be causing this issue - perhaps something related to the use of __dirtyPosition?

EDIT: I experimented without using the clone() method and instead creating a new second box from scratch, but sadly, the outcome remains unchanged.

EDIT 2: It's important to note that despite the simulation running smoothly, I am unable to get the collision listener to function correctly.

Answer №1

Relevant GitHub Thread

After reviewing the code, it appears that the clone method belongs to THREEjs rather than Physijs. This means that only the physical material, not the physical mesh, is being cloned in your current implementation. To properly clone both the material and mesh, you will need to create a new BoxMesh using similar logic as what was done for c.

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

To close the responsive menu, simply click anywhere outside of the navigation bar

My issue involves a responsive menu with Bootstrap. On desktop, the menu closes fine; however, on the responsive view, I want it to close when clicking outside of the nav menu in any area. Here is my navigation code: <!-- Navigation --> <nav id= ...

React component causing function to fire twice on click

Summary: My toggle function is triggering twice upon clicking the button. Within a React component (using Next.js), I am utilizing the useEffect hook to target the :root <html> element in order to toggle a class. The script is as follows: useEffect( ...

Is it possible to place Angular Material components using code?

Currently, I'm in the process of creating a responsive Angular application. Is there any way to adjust the height and position of the <mat-sidenav-content></mat-sidenav-content> component in Angular Material programmatically without relyi ...

Optimizing react onClick events to allow for multiple functions to be executed efficiently

I am currently developing a react button component that takes in one function as a prop to be run when the onClick event occurs. <Button onClick={() => console.log('hello')}> This translates to <button onClick={onClick}> Say hel ...

Is it unorthodox to utilize constructor instances as prototypes in "WebGL - Up and Running"?

In the book "WebGL - Up and Running," a unique custom geometry is created in a rather straightforward manner. However, what caught my attention was the penultimate line of code. Here's how it looked: Saturn.Rings = function ( innerRadius, outerRadius ...

How can I update a specific element within an array of objects in JavaScript based on its reference rather than its index position?

I am dealing with multiple arrays of objects x=[ {a:1}, {b:2}, {c:3}, {d:4} ] y=[ {e:5}, {f:6}, {g:7}, {h:8} ] (etc) and I have a list of references pointing to the objects I need to replace. Instead of having an index into the array, I hold reference ...

Exploring the capabilities of window opener in AngularJS applications

I am facing an issue with a function that utilizes an API to redirect me to a callback URL. After this redirection, I need to execute a function in my core JavaScript. If I keep the function separate from AngularJS and use window.opener, it works fine. How ...

Exploring nested arrays in JSON through iteration

Here is the JavaScript code I am working on (the "data" variable is retrieved from a json call): if (data.projectReports.length) { for (var i in data.projectReports){ var report = data.projectReports[i]; $('#reports').append( & ...

An Angular JS interceptor that verifies the response data comes back as HTML

In my current Angular JS project, I am working on implementing an interceptor to handle a specific response and redirect the user to another page. This is the code for my custom interceptor: App.factory('InterceptorService', ['$q', &ap ...

What is the best method to modify the inner HTML of a recently added element?

<script> $(document).ready(function(){ $(this).on("click", "#add", function(){ var html = ' <div id="trav"><div class="adults"><p>Adults</p><div class="buttons&q ...

During the installation of a package, npm encountered a require stack error with the code MODULE_NOT_FOUND

Whenever I attempt to install something using the npm install command, it throws an error saying "require stack" and "code MODULE_NOT_FOUND" C:\Users\dell>npm audit fix node:internal/modules/cjs/loader:1075 const err = new Error(message); ...

Handling ajax errors when connection to the internet is disrupted

When working with ajax calls, I have encountered an issue with the "error" handler not functioning correctly when the internet connection is lost. Is there an alternative handler that can be used for these scenarios? $.ajax({ type: "GET", ur ...

Ways to reduce lag while executing a for loop

How can I optimize my prime number generation process to avoid lagging? For example, is there a way to instantly display the results when generating primes up to 1000? HTML: <!DOCTYPE html> <html> <meta name="viewport" content="width=dev ...

React seems to be frequently throwing errors related to undefined variables

What I'm attempting to do is repeat a React element a certain number of times. I've used a for loop in the past with simple HTML elements and it worked fine. However, now I'm encountering an error stating that the 'fields' array is ...

How can HTML content be stored in a variable using JavaScript?

Today, I delved into JavaScript basics and managed to create a simple HTML page that allows users to add or remove list items. While I am aware that there are more advanced solutions out there, I believe that for my learning process, this accomplishment is ...

Enhancing v-data-table by implementing a dynamic counter feature, complete with buttons for increasing and decreasing the displayed number

Having an issue with data retrieval from an API that lacks a 'count' property, I am required to create a new array and utilize it in the v-for loop. I aim to assign a specific number to the counter so that upon clicking the add button on each ro ...

Techniques for routing users while retaining POST data in ReactJS

Is it possible to redirect a user to an external URL with POST data in ReactJS? I am trying to redirect the user to an external bank deposit link, but the bank link does not respond with a redirect URL as expected. I believe I need to make a POST request ...

Display the scrollbar in a Boostrap CSS table when the content exceeds the height of the div

I've been working on a Bootstrap page that looks like this: https://i.sstatic.net/kpHMM.png On the right side, there are two tables inside a div. The issue I'm facing is that when the tables contain too many elements, they grow in height instea ...

Prevent onlick actions until JavaScript function has completed

I run a dynamic quiz website using PHP, JavaScript, and MySQL. The quiz consists of multiple choice questions with answer options displayed on four buttons. <input type = "button" value="$alt1" onClick="changeQuestion('alternative1'); this.st ...

issue with JavaScript canvas

My task is to develop a Blackberry application, but I have limited knowledge in Java. Since the application requires drawing capabilities, I decided to use HTML5 and JavaScript instead. I started reading some JavaScript tutorials to prepare for this proj ...