3
votes

I'm new to Three.js, so if this is obvious then apologies upfront.

I set my camera using the LookAt method, and would like to move along that vector when pressing a key on the keyboard.

I've tried mimicking the feature by subtracting the camera vector from the point I'm looking at via subVector, normalized the resulting vector, then did something along the lines of:

camera.position.x += lookAtVector.x
camera.position.y += lookAtVector.y
camera.position.z += lookAtVector.z

...but I appear to be drifting a bit and not moving toward the lookAt point when I do this. How can I move along a lookAt vector in three.js?

1

1 Answers

8
votes

The camera is looking down it's negative-Z axis, so you want to do this:

camera.translateZ( - distance );

three.js r.57