chandlerprall / Physijs

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

PhysiJS 2.0 / Goblin Physics - findSupportPoint - Cannot read property "x" of undefined error when angular_factor and velocity_factor is set to 0 #310

Closed Andrews54757 closed 5 years ago

Andrews54757 commented 5 years ago

Using the 2.0 branch, I found this error:

screen shot 2018-08-03 at 4 23 44 pm

Upon researching why this error happened, I found out that it happens when an object collides with another when the object is "frozen" with angular_factor and linear_factor.

Internally, this error is caused by the direction argument in the findSupportPoint function with the value of Vector3 {x: NaN, y: NaN, z: NaN}. The function is called in the addPoint function and passes next_direction to findSupportPoint(). The direction is NaN because the positions of the objects become NaN in goblin.

chandlerprall commented 5 years ago

Thanks for digging into what triggers it! Do you have a simple setup to reproduce this?

Andrews54757 commented 5 years ago

Yes, I do have a setup:

https://andrews54757.github.io/PhysiJS2-Test/error.html

Code is visible here:

https://github.com/Andrews54757/PhysiJS2-Test

chandlerprall commented 5 years ago

Sorry for the delay looking into this. Thank you for all the initial info, and that simple test case!

You've over-constrained the system, and the NaN is it blowing up in response :)

Instead of restricting the box's movements along all 6 degrees of freedom (setting all factors to 0), set its mass to Infinity. The engine looks specifically for this mass and treats those objects differently.

Andrews54757 commented 5 years ago

Thanks for your help! That seems to work!