ThreeJS绕着运动点的轨道摄像机

时间:2018-12-28 23:31:08

标签: javascript three.js

我正在尝试使用“轨道控制”来绕开实体的位置,但是当实体移动时,摄影机基本上不会像可旋转的第三人称摄影机那样跟随该点。我是Threejs的新手。

这是我到目前为止所得到的:

class Camera {
constructor() {
    this.fov = 75;
    this.near = 1;
    this.far = 4000;
    this.angle = Math.PI / 6;
    this.cameraAdditions = new THREE.Vector3();
    this.entityToFollow = null;

}

init() {
    this.TJS_camera = new THREE.PerspectiveCamera(this.fov, window.innerWidth / window.innerHeight, this.near, this.far);
    this.TJS_camera.position.z = 2;
    this.TJS_camera.position.y = 2;

    this.controls = new THREE.OrbitControls(this.TJS_camera);

    ProjectA.Game.getScene().add(this.TJS_camera);
}

setEntityToFollow(entity) {
    this.entityToFollow = entity;
}

update(delta) {

    if (this.entityToFollow && this.entityToFollow.getObject()) {
        let entityObject = this.entityToFollow.getObject();
        if (entityObject.scene != null) {
            entityObject = entityObject.scene;
        }

        const camera = this.TJS_camera;

        this.controls.target.set(
            entityObject.position.x,
            entityObject.position.y,
            entityObject.position.z
        );

        this.controls.update();
    }
}} window.PACamera = Camera;

0 个答案:

没有答案