As I work on creating a shooter in three.js, I've encountered an issue. When I change my aim left and right, the bullet fires in the correct direction. However, when I adjust my aim up and down, the bullet moves in those respective directions but doesn't rotate accordingly.
for (let index=0;index<bulits.length; index+=1){
if (bulits[index] === undefined) continue;
if (bulits[index].alive == false){
bulits.splice(index,1);
continue;
}
bulits[index].position.add(bulits[index].velocity);
}
if (keys.z && gunn){
let bullit= new THREE.Mesh(
new THREE.SphereGeometry(0.05,8,8),
new THREE.MeshBasicMaterial({color:0xffffff})
);
bullit.position.copy(swordPosi);
bullit.alive = true;
bullit.velocity = new THREE.Vector3(
-Math.sin(camera.rotation.y),
Math.sin(swordRotation.z), // the sword is just the name of the guns cannon.js hit box
face
);
setTimeout(function(){
bullit.alive = false;
scene.remove(bullit);
}, 1000);
bulits.push(bullit);
scene.add(bullit);
}