Sign in to follow this  

Computing Direction Vector in 3D

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this