Orbit-camera setting zoom distance with a tween

Hi, Im using the orbit-camera script and I want to tween the current distance between the camera and its target using the tween library but I cant figure out how to access the variable (what is the variable I need?) to make the move.

I’m guessing it should be something like this but I dont know what variable to use…

this.cameraScript.tween(this.cameraScript.currentDistance()).to(newDistance), this.tweenTime, pc.SineOut).start();


Project sample reference: Orbit camera | Learn PlayCanvas

Refer to the mouse and touch controls where they zoom in/out:


MouseInput.prototype.onMouseWheel = function (event) {
    this.orbitCamera.distance -= event.wheel * this.distanceSensitivity * (this.orbitCamera.distance * 0.1);

this.orbitCamera is the a reference to the orbit camera script. distance is the distance from the camera to the focus point

Thanks but when I do something simply like:


(where this.orbitCamera refers to the orbitCamera script on my camera), it has no effect on the camera at all.

Im not sure what Im doing wrong.

Should work unless some other script is also updating the property. Also, check the min/max distance limits on the orbit camera.

I would recommend to start debugging in the orbit camera script on the distance property to see what values it is being updated with

Just tried it directly in the project and it seems to be working fine as long as the number is within the limits of distanceMax and distanceMin

Aah, it looks like its not working because the cameras target position is tweening at the same time. I guess this must be overriding it. Pity I cant seem to do both at the same time but I guess this will do.