I’m experimenting with using react-three/rapier as my physics engine, however I can’t get a camera to follow the position of a Rapier object. The camera follows the object as it falls down the z axis, but as soon as it hits the ground and bounces around the camera bounces around on a seemingly different target, I’ve created a sandbox to show this here:https://codesandbox.io/s/solitary-snowflake-199g3k
As you can see from the below gif, the camera follows the box as it falls, but then pans wildly after impact with the floor
The Mesh position never changes, it simply stays at the initial values so this isn’t an option unfortunately,
Thanks for the demo @notchris , however looking at the demo am I right in thinking that in your demo the camera position is just tied to the y axis, so the camera ‘falls’ in time with the object, but the lookAt is never changed?
There’s a couple issues at play here and I wanted to show you the correct way to resolve what’s happening.
First here’s a updated sandbox: r3f-rapier updated camera follow - CodeSandbox
First thing I did differently is just to clean it up I imported the Box shape from Drei. This is the same thing as the React-three-Rapier demos, to help it be cohesive.
Next I moved the position props off the mesh and onto the RidgedBody where they belonged
The main thing to remember is that there’s two worlds happening in parallel. Rapier to simulate and test/solve collisions, and ThreeJS to render.
So WHILE YOU CAN take vector, position, and other data from one sim to the other I’d be very careful about it.
In the first example the position of the ridged body was never correctly set the first time (was at 0) so of course it never fell. (translate didnt update)
But the mesh inside it did? I dont know that part gets confusing
Then, USING THREE you animated it falling in space instead of letting Rapier do it…
Also, there’s an invisible floor collider on the scene, so it’s just got a thing to bounce off of but nothing is setup to render in Three (I left that)
Anyway, moving props to the ridged body correctly initializes rapier which then updates correctly with translation() so the rest works as it should