chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.75k stars 455 forks source link

Collision events are not reliably fired #287

Open TimDix opened 7 years ago

TimDix commented 7 years ago

I've forked the Jenga game and I'm trying to detect collisions between the table and the blocks, I've forked the game, and then added the following:

table.addEventListener('collision', function( other_object ) {  
    console.log('table collision', other_object); 
});

Dragging blocks off the tower, and letting them fall onto the table, I expect to see a collision event fired, but I usually don't. I notice that the blocks towards the bottom of the stack behave differently than the ones towards the top, but still not really what I expected: drop a block onto the table, get a collision event.

https://timdix.github.io/Physijs/examples/jenga.html

I'm very new to both Three.js and Physijs, any suggestions are greatly welcome.

TimDix commented 7 years ago

http://screencast.com/t/fJzfSETVbQI

TimDix commented 7 years ago

It appears that it might be related to the issues this guy was having:

https://japhr.blogspot.com/2012/08/more-physijs-collisions.html

"But it seems that subsequent collision events are not fired if any object is mid-collision with any object."

Maybe because of the stacking of the blocks, the events aren't getting fired? Any suggestions at all would be greatly appreciated to work around this issue, even hacks ;)

chrisnyc commented 7 years ago

Hi, I was also not able to get collisions working in my project, but I saw that they worked on this page: http://chandlerprall.github.io/Physijs/examples/collisions.html so I figured that the problem must be on my side. I copied that example site exactly to my local machine and pointed my local web server at it as the root. What I found was that it would not work if I accessed it by http://localhost/collisions.html (gave no errors in Chrome debugger either) , but it worked perfectly if I used http://192.168.0.8/collisions.html (or the hostname on my local domain). Pretty strange, but hopefully this work-around solves the problem for you until the root cause can be identified and fixed.

chrisnyc commented 7 years ago

Ok, so after a bit more investigation, it seems like changing the hostname is just a way of forcing a cache miss of some sort. The real problem seems to be with a newer version of three.js or physi.js. I'm looking at this hard and I hope to figure it out soon.

chrisnyc commented 7 years ago

Ok, so after finding the "disable caching" checkbox in the Chrome developer window settings..... I figured out the issue is with ammo.js. The latest version of ammo.js silently breaks collision detection. Reverting to the version of ammo.js included with the example http://chandlerprall.github.io/Physijs/examples/collisions.html solves the issue. I am continuing to dig into this because I think the newer version of ammo.js is faster and I'd like to use it...