Archived

This topic is now archived and is closed to further replies.

Vectors - where am i going?

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

Recommended Posts

im having trouble structuring my movement in OOP for my game engine. and i have questions about methods: 1) should i put my movement class in the object class, then allow its parent cGame class call the appropriate functions? 2) addition question: im using directdraw, but a lot of people talk about vectors when on the topic of movement. what are vectors and should i use them for 2d directdraw stuff (there is no rotation, radians etc in my game). the way ive done movement in the past was: sprite.x += sprite.speed; is this wrong? ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you!

Share on other sites
this will be quite wrong, if youre not moving along the x or y axis. imagine a car thats going 5m/s. its moving to the left, you add 5m after one second and everything is fine. no its turning 45deg and moving left and up. adding 5m to x and y will make it move 7m.

but: did they never tell you about vectors in school? the position of your object (x,y) would be a vector, the direction its moving is a vector (if left the vector would be (1,0))..

you can imagine it as an arrow.. a unit vector has length 1, a point in space can be seen as vector from the origin to the object (though vectors dont have a position and usually are at the origin)

just get a book about linear algebra, that should contain vectors as well as all the things you can do to them (dot product, vector product, etc.)

its not hard to get but think of it like this: it sounds much better to say "im mirroring the direction vector on the y axis" instead of "im doing x=-x" ,-)

Share on other sites

1. Direction
2. Position

you also have a value SPEED.

Now, this is the correct way of calculating your POSITION vector

Position.x+=Speed*Direction.x;
Position.y+=Speed*Direction.y;
Position.z+=Speed*Direction.z;

I hope this helped!

Share on other sites
i understand the part when you go:
Position.x+=Speed

but what is meant by the part when you multply it by Direction.x, is that -1 or positive 1, or what?

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• Forum Statistics

• Total Topics
632948
• Total Posts
3009406
• Who's Online (See full list)

There are no registered users currently online

×