How do I change the camera rotation center in the script?

Currently I am writing an effect:
1.the camera can be moved to different places
2. when the camera moves to point A, the center of rotation is some object,camera focus on object
3. when the camera moves to point B, the center of rotation is the camera itself
How do I change the camera rotation center in the script?
the camera script I used is orbitCamera.js

Hey @leooooooo,

While you can’t change the camera’s pivot (center of rotation) directly, you can simply make it a child of an empty entity and rotate that empty entity instead. The empty entity will effectively become a pivot. When you no longer want the entity to be the centre of rotation, simply unparent it from the camera. This should be the simplest and most straightforward solution to your problem.

the camera binging orbitCamera.js can rotation itself?

Sorry, I’m not sure I understand what you mean?

like this

Hey, you can call the following function in orbit camera script to get the desired results

1 Like

You could try in a separate script to make a simple solution, like so:

cameraEntity.rotate(0, this.rotationSpeed * dt, 0); // OR
cameraEntity.rotate(0, this.rotationSpeed * -1 * dt, 0);

You could then trigger the rotations to either direction based on whatever keypresses you desire, such as A or D:

if (this.app.keyboard.wasPressed(pc.KEY_A)) {
        cameraEntity.rotate(0, this.rotationSpeed * -1 * dt, 0);
    } else if (this.app.keyboard.wasPressed(pc.KEY_D) {
        cameraEntity.rotate(0, this.rotationSpeed * dt, 0);
    }

Can this be done using mouse events?

Can this revolve on its axis using mouse events?

Yes, so basically after setting the new world position, the orbit camera script will consider it as a center of rotation and all mouse events will work accordingly.

1 Like

okay,I’ll try to do this.thx