# How to move an object in 3D space

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

## 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 on other sites

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 on other sites
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 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.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633330
• Total Posts
3011385
• ### Who's Online (See full list)

There are no registered users currently online

×