Public Group

# Computing Direction Vector in 3D

This topic is 3658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi All, I'm making a 3D game in which when the Arrow is fired, the Camera will follow the Arrow. (note, mPosition is the 3D vector containing the position of the arrow) mCam->PositionCamera(mPosition.x-9,mPosition.y+2,0,mPosition.x+10,mPosition.y,mPosition.z,0,1,0); The above line of code works but only if the Arrow is kept in its initial position (this is when the cam and arrow share the same X position). If the Arrow is pointed in a different direction, the cam will move but along its own x, y and z. Any help will be greatly appreciated. Thanks.

##### Share on other sites
Oh btw, a friend of mine told me I would need to point the cam in the DIRECTION of the Arrow, for this I would need a direction vector on each of my objects.

which is why im askin how to calculate a direction vector.

Also exactly which part of my cam would i insert the directions in? :-\$

##### Share on other sites
Someone? im really short on time and this is seriously killing me!

##### Share on other sites
Your post doesn't really make clear what sort of behavior you're after. By 'follow' the arrow, do you just mean to track its motion? (That is, as if the camera were mounted on a tripod, but was being panned, tilted, and perhaps zoomed so as to keep the arrow in frame.) Or do you mean you want it to 'physically' follow the arrow (for example, to always be positioned a little behind and above the arrow, and pointed in the same general direction as the arrow is travelling)?

##### Share on other sites
normalising the vector will give you the direction of the arrow.

then just move the camera along that vector

edit: your going to need more than the position. surely you have the velocity of your arrow? normalise THAT vector and u have your direction

##### Share on other sites
All you need to do is see what the direction vector is for the arrow.

The calculate the offset for the direction. Add that to camera's position. And you are done.

theTroll

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633708
• Total Posts
3013468
×