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 137 forks source link

Ammo kinematic transforms break when combined with THREE's .attach() #131

Open chrisnovello opened 5 years ago

chrisnovello commented 5 years ago

Trying to combine THREE's recent .attach() https://github.com/mrdoob/three.js/pull/16528 with Ammo's kinematic bodies. The ammo bodies don't seem to transform as expected

https://glitch.com/edit/#!/ammo-grab https://ammo-grab.glitch.me/

@InfiniteLee suggested

huh yea it looks like the collider's transform gets totally messed up whatever attach is doing must not be playing nice with how ammo-body grabs the world transform for kinematic bodies i would do some debugging in ammo-body syncToPhysics

This is attempting to use .attach() as a way to keep a physics object firmly locked onto a hand as it moves (even just visually, it is alright if the physics body lags a tiny bit behind)

Hoping this could become a definitive approach to this very commonly desired feature (also haven't thought about if it would be viable in NAF)

https://github.com/donmccurdy/aframe-physics-system/issues/81 https://github.com/aframevr/aframe/issues/2425

chrisnovello commented 5 years ago

following up...

Kevin Lee i had an idea just now about what the issue probably is. https://github.com/donmccurdy/aframe-physics-system/blob/6cb498263f0ac6401b5784bce24a5b827e3e7ffc/src/components/body/ammo-body.js#L380

there's this check for the parent of the entity to see whether or not it should try to calculate the world transform or not if attach is doing something where its not actually parenting the grabbed object under the hand, it will still try to use the local transform which would explain why the collider appears in the ground (at origin) that check is probably not super necessary (it was just a perf saving attempt on my part) but you can hack around the issue by nesting the objects under an empty entity not ideal though

which indeed works !

https://grab-again.glitch.me/ https://glitch.com/edit/#!/grab-again

if you opened that issue already, feel free to mention that. I'll have to think about whether or not that check is important or not...