larryq
larryq

Reputation: 16309

Move the camera along its LookAt axis in Three.js?

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?

Upvotes: 3

Views: 5658

Answers (1)

WestLangley
WestLangley

Reputation: 104843

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

camera.translateZ( - distance );

three.js r.57

Upvotes: 8

Related Questions