Set Camera Position Problem

Hello
Im trying to move my camera from one position to another and LookAT other object
Already create a script that set a new position to the camera or another object
but when i try to orbit the camera after i set the new position, the camera return to the original position.

This is my script its very simple.

var MoveCam = pc.createScript('moveCam');

MoveCam.attributes.add('Cam', {type: 'entity'});

MoveCam.attributes.add('Pos', {type: 'vec3', default: [0,0,0] });

MoveCam.attributes.add('Target', {type: 'entity'});

// initialize code called once per entity

MoveCam.prototype.initialize = function() {

        this.entity.element.on('mousedown', this.onMouseDown, this);

};

MoveCam.prototype.onMouseDown = function() {

    var position = this.Target.getPosition();

    this.Cam.setPosition(new pc.Vec3(this.Pos.x, this.Pos.y, this.Pos.z));

    this.Cam.lookAt(position);

};

any help it’s very appreciated

Hi @Arthur,

Yes, that’s expected for the orbit camera script. It uses internally a pivot vector to update the position of the camera, so you will have to update that to match your new camera position.

If you search through the forum you will find a number of related posts on the subject, here is one:

2 Likes