R3F Cannon Ball stops moving

Hi all, I’m having an issue getting this scene to work. I’m referencing code from tpl-r3f - CodeSandbox

I have a ball that can be controlled with WASD. This is using drei KeyboardControls. Using Rapier to import Cannon.
Here’s the code for the ball t4/ball.tsx at 6c06b2647d35467c2083d2d023860a16c383960d · victorsh/t4 · GitHub
And here’s the code for the scene
t4/rapier-scene.tsx at 6c06b2647d35467c2083d2d023860a16c383960d · victorsh/t4 · GitHub

The issue that I’m having is that once the ball stops moving, the ball no longer moves again. When the scene first loads, I can move the ball with WASD. I logged the functions connected to keyboard and it seems to be working fine. Within ball.tsx, I can see that torque and impulse are being applied.

Any help is much appreciated!

Maybe the ball went sleeping. In cannon-es (which is a maintained fork of cannon) bodies can go into sleep mode, thus preserving computational resources. There is method wakeUp, that wakes the body and it becomes again active. I don’t know whether the same applies to original cannon or to R3F’ed cannon, but you can try to wake the ball.

Awesome! I added wakeUp to the rigid body and now it keeps moving on keyboard input. Thanks so much! This was the way.

1 Like