Developing a 3D shooter on ThreeJS. The weapon rotates along the Y axis depending on the direction of the camera. You also need to turn it up and down, depending on whether the camera is looking up or down. What proper formula should be?

weapon.rotation.set( controls.getObject().rotation.x, controls.getObject().rotation.y - Math.PI, controls.getObject().rotation.z ); 

    1 answer 1

    It all depends on what you need to get in the end.

    Options:

    a) Place the camera in the scene, make the object of the child a child of the camera: scene.add(camera); camera.add(weapon); scene.add(camera); camera.add(weapon);

    b) Use quaternions : weapon.quaternion.copy(camera.quaternion);