I am currently working on a simple FPS game using Three.js
and PointerLockControls
. My goal is to attach a weapon to the camera/controls.
Although I have managed to position the gun in front of the camera and move it along the x/y axis, I am facing an issue with its movement along the z axis (up/down).
function updateGun() {
if (weapon) {
const yaw = controls.getObject();
weapon.position.set(
yaw.position.x - Math.sin(yaw.rotation.y) * 3,
yaw.position.y - 1,
yaw.position.z - Math.cos(yaw.rotation.y) * 3);
weapon.rotation.set(
yaw.rotation.x,
(yaw.rotation.y - Math.PI),
yaw.rotation.z);
}
}