Camera Orbit Offset After Reset

I’m resetting the camera using:

this.baseCamera.setCameraAndLookTarget(cam);

This works correctly in most scenarios. However, on some occasions, although the camera returns to the expected position and view, it appears to lose its orbit center.

As a result, when the user starts rotating the camera, it rotates around a much larger radius instead of the intended pivot point.

I’ve attached a video demonstrating the issue for reference and have also submitted a bug report.

Link: Transfer - Dropbox

The issue is likely that setCameraAndLookTarget expects two arguments: the camera position and the look target (orbit center). You’re only passing one object (cam). If cam doesn’t contain both positions, the orbit target defaults to (0,0,0) or whatever was last set, causing the large radius.

Try this:

this.baseCamera.setCameraAndLookTarget(
  cameraPositionVector,   // Vector3
  lookTargetVector        // Vector3
);

If you need the current look target, read it from OrbitControls.lookTarget before the reset. This is a setup issue, not a bug.

4 replies left
Reply to this post directly if you need further help (bottom right button)

Hello @Ashokkumar_KR

The AI is correct here and this method expects two arguments, please see our API documentation: OrbitControls | Needle Engine. If you just want to set the lookAt target (orbit center) or just the camera position please use the respective methods.

setCameraAndLookTarget(source: Object3D | Camera, immediateOrDuration?: number | boolean): boolean;

It expects a camera, and I’m passing it?

But it does also set the orbit point by raycasting:

source: The object to raycast from. If a camera is passed in the camera position will be used as the source

If you just want to set the camera position you can use OrbitControls | Needle Engine (if you have a Camera component you can pass in camera.gameObject to access the Object3D)

Even in that case, the output should be the same, right? I’m passing the exact same cam object in both scenarios.

In around 90% of cases, this.baseCamera.setCameraAndLookTarget(cam) produces the expected result. However, in some cases, the camera moves to the correct position and orientation, but the orbit target seems to become offset.

In the bug report I shared, I’m passing the same cam to the same mainCamera in both scenes. One scene behaves correctly, while the other ends up with an incorrect orbit pivot?

Hello, i took a look into your Bugreport Project.

With this specific object the raycasts from setCameraAndLookTarget go through the holes in the mesh.

So in this case, i would recommend to use setLookTargetPosition and setCameraTargetPosition methods from OrbitControls to set the camera view and look target point.

Just a note: If you use AI for your work we recommend that you install the Needle Engine AI skill (or use our MCP) for additional help: AI & Needle Engine | docs

Hello, did the previous reply answer your question? Did you try the suggested method?

yeah. I used the suggested methods, and initial impressions it looks fine.

This is what i came up with

setCameraAndTargetForBaseCamera(cam: Camera) {




    if (!cam || !this.baseCamera)

      return;




    const model = ComponentDataContainer.instance.goTarget;




    if (!model)

      return;




    const source = cam.gameObject;




    this.baseCamera.setCameraTargetPosition(

      source

    );




    const box = this.modelBox || new Box3().setFromObject(model);

    const center = new Vector3();




    if (box.isEmpty()) {

      center.copy(model.worldPosition);

    }

    else {

      box.getCenter(center);

    }




    const distance = source.worldPosition.distanceTo(center);




    const forward = new Vector3(0, 0, -1)

      .applyQuaternion(source.worldQuaternion)

      .normalize();




    const target = new Vector3()

      .copy(source.worldPosition)

      .addScaledVector(forward, distance);




    this.baseCamera.setLookTargetPosition(

      target

    );

  }