Is setPosition different for Camera vs Model?

I am using the Model Viewer Starter Kit and using external html to control my models. I have looked over the docs and api and spent way to many hours trying to figure it out. Here is what I have for code. It will move any model but not the camera.

var myCam ="Camera")
var p = myCam.getPosition();
myCam.setPosition(p.x + 1,p.y,p.z);

from what I have read I think the orbit-camera.js may be overwriting this external button code?


Haven’t use that project in a while, but yes it sounds like it is being overwritten. If nothing else was getting involved then that code you have would work.

Yup, orbit-camera.js does indeed set the position of the camera every frame. Here’s the update function:

OrbitCamera.prototype.update = function(dt) {
    // Add inertia, if any
    var t = this.inertiaFactor === 0 ? 1 : Math.min(dt / this.inertiaFactor, 1);
    this._distance = pc.math.lerp(this._distance, this._targetDistance, t);
    this._yaw = pc.math.lerp(this._yaw, this._targetYaw, t);
    this._pitch = pc.math.lerp(this._pitch, this._targetPitch, t);


And _updatePosition does:

OrbitCamera.prototype._updatePosition = function () {
    // Work out the camera position based on the pivot point, pitch, yaw and distance
    this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0);

    var position = this.entity.getPosition();

So no matter what position you set the camera to externally, this script will just overwrite it.

There is a function on the orbit-camera script called resetAndLookAtEntity which allows you to position the camera and look at another entity. Line 139

There is also resetAndLookAtPoint to position and look at a point on line 116.