pmndrs / use-cannon

👋💣 physics based hooks for @react-three/fiber
https://cannon.pmnd.rs
2.73k stars 153 forks source link

Add cannon bodies to CollideEvent #380

Open ffdead opened 2 years ago

ffdead commented 2 years ago

I'm looking for a way to reset the position of an InstancedMesh when it collides with a ground plane. So when it collides, I would want to update the position and velocity of that instance's physics body.

But it seems there is no way to get the current instance index from the onCollide callback. Similar question here: https://github.com/pmndrs/use-cannon/discussions/106

Would it be possible to directly expose the physics bodies in addition to the Object3D in the CollideEvent?

isaac-mason commented 2 years ago

Adding the instance index in the onCollide callback sounds like a doable change.

Unfortunately exposing the cannon-es physics bodies isn't possible though, as the bodies are created inside a web worker.

isaac-mason commented 2 years ago

If you're referring to exposing the physics body APIs returned from the body hooks, that would be doable! Just dawned on me that you might be referring to that.

ffdead commented 2 years ago

If you're referring to exposing the physics body APIs returned from the body hooks, that would be doable! Just dawned on me that you might be referring to that.

Ah yes, I think that would be enough - sorry for being unclear. The purpose would be to be able to reach to a colllision event and add forces manually or modify the position of the bodies that collided.