3

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 Answer 1

8

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

camera.translateZ( - distance );

three.js r.57

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Didn't know I could do that with translateZ. I guess the translate(X|Y|Z) methods work in object space, whereas something like camera.position.(x|y|z) is in world space?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.