Jump to content
  • Advertisement

Archived

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

Neen10do

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.

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

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


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Think about this, when your car is moving, you have 2 vectors.


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


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

Share this post


Link to post
Share on other sites

  • 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!