2

I'm thinking it requires getting a direction vector, and the coordinates and multiplying them, although I don't know how to do that nor have I been able to find the information.

JVE999
  • 3,327
  • 10
  • 54
  • 89

1 Answers1

3

The direction from camera to object is:

var direction = object.position.clone().sub( camera.position ).normalize();

Or, if by "in the camera direction" you meant in the direction the camera is facing, the way to get that direction has been previously answered.

To move object 10 units in that direction:

object.position.add(direction.clone().multiplyScalar(10));
Community
  • 1
  • 1
IceCreamYou
  • 1,852
  • 14
  • 25
  • I was looking at the data in the direction vector and I'm not sure how it's calculated. At first I thought it might be three angles, but apparently it's not. How would I shift the direction (when I move, the object flies outward in a different direction, so I'd like to adjust it). – JVE999 Aug 21 '13 at 18:12
  • Each axis in my `direction` vector above holds values from -1 to 1 such that multiplying the direction vector by a distance (above, `10`) yields a point the given distance in the relevant direction. If you just keep doing these calculations every frame they will continue to be relative to the camera position even as it moves. – IceCreamYou Aug 21 '13 at 21:46
  • I set the direction before the loop, so it stays on path. Is there a way to move the direction relative to the camera? I imagine changing a value in `camera.position` might do that? – JVE999 Aug 22 '13 at 05:16
  • Is there a reason you can't just change the direction you set for the object when the camera moves? – IceCreamYou Aug 22 '13 at 05:17