0
\$\begingroup\$

I have a camera at position P, and a normalized direction vector D (where the camera is facing). I want the target of the camera to be 5 units forward from the position. Here's my attempt:

F = (0, 0, 5) // forward
target = P + (D * F)

The obvious problem is that D * F can eventually reach (0, 0, 0), which would cause the target to be equal to the initial position. I feel like I'm missing something even more obvious than the problem here but, how would I properly have the target be 5 units forward?

\$\endgroup\$
1
  • \$\begingroup\$ It's correct if and only if D has length of one... is that what you're getting at? \$\endgroup\$ Commented Feb 14, 2015 at 7:14

1 Answer 1

0
\$\begingroup\$

I was missing something incredibly obvious that makes me feel ashamed to have posted this question. All that needed to be done was to set F = (1, 1, 5) instead of zeroing out the coordinates I didn't need. It's like I forgot how to multiply.

\$\endgroup\$
1
  • \$\begingroup\$ Simply multiply your unit vector with a scalar target = P + D * 5, that way you don't have to match up the F vectors components with the direction of your unit vector. Also select your own answer as the accepted answer, if you don't the website will automatically bring your question up to the front page periodically until you do. \$\endgroup\$ Commented Feb 14, 2015 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .