n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.
https://n5ro.github.io/aframe-physics-system/
MIT License
507 stars 138 forks source link

Inconsistent results across browsers for spawned dynamic-body rotation #72

Open gregfagan opened 7 years ago

gregfagan commented 7 years ago

Scene demonstration: https://aframe-physics-rigidbody-issue.glitch.me/ Code: https://glitch.com/edit/#!/aframe-physics-rigidbody-issue?path=index.html:1:0

When dynamically spawning dynamic-body entities, some browsers (Firefox, Safari, Chrome) do not properly allow the yellow box, spawned after setTimeout, to rotate. Edge appears to behave correctly. The worker driver appears to fix the issue.

See the discussion beginning here: https://aframevr.slack.com/archives/C0FAACNA0/p1509646499000081

donmccurdy commented 7 years ago

Hm, if I include a delay before adding the dynamic-body it also fixes things:

https://glitch.com/edit/#!/aframe-physics-rigidbody-remix?path=index.html:11:31

Seems like some kind of race condition but I'm not sure what's going on yet.

wmurphyrd commented 7 years ago

Also if you wait for the entity to load before adding dynamic-body, it works

https://glitch.com/edit/#!/cream-can?path=index.html:12:0

donmccurdy commented 7 years ago

and calling el.body.updateMassProperties() (after the box is "stuck") fixes it too. 🤔

gregfagan commented 7 years ago

Thanks for taking a look at this, I was able to fix the issue in my project with the loaded event -- thought I had tried everything! Turns out I had only tried waiting until the body-loaded event to set up my entities.