Closed mz8i closed 10 months ago
Thanks for working on this @Soham1803
The body props type has both a rotation
(euler) and a quaternion
prop.
We should update props-to-body.js
to support the quaternion
prop as well as rotation
, rather than treating rotation
as a quaternion.
Won't these lead to conflicts if we have two different props handling the same property of the body?
We'd just need to prefer one if both are provided, we can document the behaviour.
Ok I got it. I hope this #437 solves it. I requested a pull for a new branch. I noticed I had unnecessary changes in my yarn.lock file pushed in the previous branch.
Thanks @Soham1803 🙂 will get this released shortly
Well, thanks to you too @isaac-mason for your guidance. 😇
The fix has been released, closing this issue
When using one of the hooks like
useBox
oruseTrimesh
, one can setrotation
inside the object returned fromargsFn
, but aquaternion
property is ignored (the body's rotation will always be reset to zero when dependencies of theuseX
hook change).A brief check in the code suggests that the problem is in https://github.com/pmndrs/use-cannon/blob/90dfc122945877b91f8d58700e3363e828a52d1b/packages/cannon-worker-api/src/props-to-body.js#L61 -
propsToBody
in the worker code only extractsrotation
from props, but notquaternion
.The workaround right now is simply to use
rotation
rather thanquaternion
, or convert quaternions to Euler angles when saving the rotation externally to later restore it. But as the API allows working only with quaternions, I think it would be appropriate to also allow users to set the body's quaternion in theargsFn
of the hooks.