Utilizing FlyControls.js
for my camera perspective
I am attempting to incorporate a projectile
into my object
The projectile is meant to utilize the angles between the camera position and the crosshair/reticle position, moving freely through 3D space
My attempt using
camera.position.angleTo(crosshair.position)
only yields a single float value. In 2D scenarios, I would employ sin
and cos
, but 3D requires a different approach
Additionally, since the projectile is in the form of a cylinder
, how do I orient it to face the direction of travel?
//how can this be achieved?
projectile.angle = {
x: ?,
y: ?,
z: ?,
};
//how can this be accomplished?
projectile.rotation = faceTowardsDestination;
function animate(){
//implementing projectile motion
projectile.position.x += projectile.angle.x * projectile.speed;
projectile.position.y += projectile.angle.y * projectile.speed;
projectile.position.z += projectile.angle.z * projectile.speed;
requestAnimationFrame(animate);
}
The projectile (cylinder) should be launched from the spaceship towards the crosshair point, while facing its intended destination https://i.sstatic.net/rfPCy.png