How to move an object in 3D space

Started by
2 comments, last by rk_theone 17 years, 6 months ago
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.
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
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.
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.

This topic is closed to new replies.

Advertisement