[SOLVED] Orbitcamera - distanceMin as preset

In relation to the https://developer.playcanvas.com/en/tutorials/orbit-camera/ tutorial, and in general, I need to make the camera start with a custom distance. For now the example is set to use the distanceMax, and not the distanceMin (or somewhere in between).

I have tried to alter the following lines:

  • within

OrbitCamera.prototype.initialize = function () {

this distance line:

this._distance = 0; - altered to; this._distance = 0.7;

  • and within:
OrbitCamera.prototype._clampDistance = function (distance) {
    if (this.distanceMax > 0) {
        return pc.math.clamp(distance, this.distanceMin, this.distanceMax);
    } else {
        return Math.max(distance, this.distanceMin);
    }
};

… altered to:

OrbitCamera.prototype._clampDistance = function (distance) {
    if (this.distanceMin < 0) {
        return pc.math.clamp(distance, this.distanceMin, this.distanceMax);
    } else {
        return Math.min(distance, this.distanceMin);
    }
};

Without luck - code does parse, but no difference at launch.

If you have ‘frameOnStart’ on start ticked, it will move the camera to ensure that entities are in the frame.

If it’s unticked, the easiest thing to do is in another script, in the postInitialise function, set the orbit camera distance to your desired distance.

Assuming it’s on the same entity as the orbit camera script:

this.orbitCamera = this.entity.script.orbitCamera;
this.orbitCamera.distance = 0.7;

Spot on, thx