What is the best way to switch the camera in the direction of mesh movement?

I want to attach a camera to the sphere and change the direction of the camera in the direction the sphere is moving so that the camera is facing the direction the sphere is moving.
What is the best way to do this?
Here is a basic example

The Free/Universal Camera have the “target” property which tell at which point the camera should be looking: Camera look at | Babylon.js Playground (babylonjs.com)

1 Like

Also @kostiunindima1 ,

I think you can use the velocity vector from the PhysicsImpostor in order to know the direction the sphere is moving towards. Attaching the camera to the sphere might not be a good idea since the sphere will be rotating vary fast because of physics, it might be tricky to make it stable.

I have update your example to get the velocity vector and use it to position the camera behind the sphere relative to the motion, this way the camera will always be look at the direction the sphere is moving and the sphere will be in front of it. We get some weird behavior when the sphere hits the ground because the motion direction changes too fast, but I think for smoother movements it should work fine.

Does that help you?

Strange behavior | Babylon.js Playground (babylonjs.com)

4 Likes

Thanks, that’s what I need!