-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to update radius args in useCircle hook? #10
Comments
This is unfortunately a limitation of the current API returned by shape hooks - there are no methods for setting shape properties. @react-three/p2 is largely a fork of @react-three/cannon adapted for p2. There was some discussion about how this might be done in the I'll mark this issue as an enhancement for now. If there's interest in this, contributions are always welcome 🙂 |
Hey!
I was trying to update the radius args of a
useCircle
hook with react three fiber but running into some problems.My current solution is to create a
useState
hook and store the radius inside of it. The radius state get updated (set state function) inuseFrame
hook. And finally make the radius state as a dependency ofuseCircle
hook. Whenever the radius state gets updated inuseFrame
hook, theuseCircle
hook then got updates with new radius, and picking up the velocity and position in the current frame.This solution work, but not very performant - on my m1 Mac mini, it runs fine in chrome but extremely jaggy on safari. I suspect the reason is that I call the set-state function in
useFrame
hook, which is explicitly advised against in r3f's documentation. However, I couldn't figure out another way to update radius.Is there any other way I can trigger the dependency updates of args in a
useCircle
hook without calling set-state inuseFrame
? Or should I not update the dependency at all? Or is there anyway I can access P2.js's native setters of args (e.g. getting access to the Body object of the component)?And btw thank you for maintaining this amazing project!!
The text was updated successfully, but these errors were encountered: