Rotating a FreeCamera around a point in space programatically

Hi again! :slight_smile:

I’d very much like to rotate my FreeCamera (not ArcRotateCamera) around a point in space programatically, so in scene.beforeRender, not using an animation.

Let’s say the point is 0, 0, 0 and the camera is at position 0, 50, -55.

Anybody willing to help me out with the math please?

scene.onBeforeRenderObservable.add(() => {
    // pls rotate around the target >:(

Thanks and much love!

demo created for you :slight_smile:

considering only x and z rotation arround a mesh


Genius, a literal god, magnificent.

Thanks a lot! Works perfectly :slight_smile:

1 Like

Hmmmm, what if I wanted to rotate the camera around a different point other than 0, 0, 0?

Don’t know why this does not work? maybe another godess can help you! :slight_smile:
I suppos that setTarget needs a relative vector?

Strange things happens when vectors are assigned to the mesh.position or positions.
If you use directly the position of the box for the target the code works.


Thanks! Now it all works :slight_smile: