How to set target for PerspectiveCamera

Hi. I am using three.js with angular 10 and have this part of code:

update() {
    if (this.isUserInteracting === false) {
      this.lon += 0.1;
    }

    this.lat = Math.max(-85, Math.min(85, this.lat));
    this.phi = ThreeMath.degToRad(90 - this.lat);
    this.theta = ThreeMath.degToRad(this.lon);

    this.camera.target.x = 500 * Math.sin(this.phi) * Math.cos(this.theta);
    this.camera.target.y = 500 * Math.cos(this.phi);
    this.camera.target.z = 500 * Math.sin(this.phi) * Math.sin(this.theta);

    this.camera.lookAt(this.camera.target);
    this.render();
  }

The problem is, the camera has no target property. How to set it?

Source code

Use the vector3()

vector = new THREE.Vector3()
vector .x = 500 * Math.sin(this.phi) * Math.cos(this.theta);
vector .y = 500 * Math.cos(this.phi);
vector .z = 500 * Math.sin(this.phi) * Math.sin(this.theta);

this.camera.lookAt(vector);
1 Like