How to put an object in front of camera in THREE.JS?

后端 未结 4 1685
野性不改
野性不改 2021-02-09 03:47

I\'m trying to put an object in front of the camera, but have not been able to.

I\'m using the FlyControls what moves the camera, and I now want to put an object in fron

4条回答
  •  借酒劲吻你
    2021-02-09 04:02

    I'm using three.js r88 and have worked out a solution starting from what Kaspar Lee posted.

    function updatePositionForCamera(camera) {
        // fixed distance from camera to the object
        var dist = 100;
        var cwd = new THREE.Vector3();
        
        camera.getWorldDirection(cwd);
        
        cwd.multiplyScalar(dist);
        cwd.add(camera.position);
        
        myObject3D.position.set(cwd.x, cwd.y, cwd.z);
        myObject3D.setRotationFromQuaternion(camera.quaternion);
    }
    

提交回复
热议问题