ArcRotateCamera.lockedTarget incorrect, setTarget correct

Hi, I found that lockedTarget does not set the cam’s target properly: it has an offset. setTarget is working fine. Is this intended or a bug?

Toggle line 30/31 and you see the diff

Underlying issue for this is that I need a way to clear the cam target. cam.setTarget(null) and cam.target = null gives error, so I am forced to use cam.lockedTarget . I hope we could use setTarget(null) one day.

Can you help?

HINT: I find a lost exclamation mark in your src code next to ‘_getLockedTargetPosition’

    /** @internal */
    public _getViewMatrix(): Matrix {
        if (this.lockedTarget) {
            this.setTarget(this._getLockedTargetPosition()!);
        }

The default target of an arc rotate camera is (0,0,0). So, if you want to reset it just call cam.setTarget(new BABYLON.Vector3(0,0,0));.

The exclamation mark is valid in TypeScript (it means that we are sure _getLockedTargetPosition will return a non null/non undefined value even if the declaration says otherwise). In any case, the code you showed is for the TargetCamera class but ArcRotateCamera overrides it with its own code.

Thanks for your answer. But I am not sure what you are saying. The lockedTarget behavior is correct and the diff with setTarget is therefore intended?

The reason I want to reset the target is because I want to enable/disable panning, which is only possible via lockedTarget = null. I toggle between two camera modes but dont need two cameras, just lock/unlock from a target is enough.

Is there a workaround?

cc @PolygonalSun who is our expert for inputs.

1 Like

So, I have a couple of questions. First, is the behavior that you want to lock onto a mesh and prevent panning away but be able to reenable panning somehow and move away from that target? Like is the purpose to lock onto something or is it just to enable/disable panning? I guess I’m asking if the mesh needs to be a part of the process (set as the camera’s target?).

Hi there ! Thanks for getting back.

Main goal is (1) to be able to enable/disable panning using the same camera in case a target is set initially. and (2) when switching between panning on and off, the camera should not change view.

I don’t need the target when in panning-mode though for me no problem in case target remains set ( i can hide it).

ping @PolygonalSun

This statement is incorrect for the arcRotateCamera. There are in fact a number of parameters you can set to control panning.
There is ‘panningSensibility’ (which you can set to a value that is way too sensitive to allow panning).
Even better, you can completely remove panning by setting the value to 0 (zero).
And then there’s also ‘panningDistanceLimit’ which you should use together with ‘panningOriginTarget’.
You do not need a second camera to modify these according to your context. You can change these values when you set the target.

Here’s an example among other options you can use:

3 Likes