Jump to content
  • Advertisement
Sign in to follow this  
rk_theone

How to move an object in 3D space

This topic is 4348 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 guys, i wanted to know how to assign a direction to an object and move it in 3d space, how to define a direction vector for an object. i know this is very basic stuff, but guys like me do exists. thanks to everyone in advance.

Share this post


Link to post
Share on other sites
Advertisement

Well I assume that your object has a position stored

in a vector:

Vector3 Position;

or in a matrix (where the translation part describes the position):

Matrix44 ObjMatrix;

Either way, to move your object into a direction, you'll need a "direction vector".

Vector3 Direction;

So, for an example, let's set the direction vector to point towards the z-axis.

Direction.Set(0,0,1);

And for every object update everyframe you'll add the Direction to the Position like:

Position += Direction;

(or use a matrix translation with the Matrix).

Now, your object is moving along the z-axis.

Cheers

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Wow, you've a long road ahead of you :)


Keep at it though.



Another way of thinking of it is to pick the place you ultimately want the object to go to, and subtract that position from your current. (As vectors). Then 'normalize' this vector (google it), and this becomes your direction vector aiming towards that location.

Share this post


Link to post
Share on other sites
thnx guys.

but i also wanted to know how to assign a direction like i wanted to go in 15 deg. to me current direction and 2 units from my current position.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!