Advertisement

movement in 2D

Started by October 06, 2002 03:10 AM
4 comments, last by littleboy55 22 years, 4 months ago
please someone help me, im trying two make an asteroids clone in 2d and i have a sprite engine but when i turn the ship i cant figure out how to get the new movement vector... ie. if the ship is turned at 90 degrees i cant figure out where the relative coords are to make a vector, thanks in advance
Take a look at NeHe's lesson 10. If you look a little, it contains all the math you would need to understand to do this.

www.FlegDev.tk
Just code it!

[edited by - flegmato on October 6, 2002 11:13:21 AM]

[edited by - flegmato on October 6, 2002 11:13:35 AM]
www.FlegDev.tkJust code it!
Advertisement
Remember rotation matrix?
Since your ship turns only about z axis. You can multiply it with the Z rotation matrix.
I doubt that this is the best way. but it is the first thing came to my mind.
(or you can look at Z rotation matrix. See what''s going on with your vector and apply it. I can''t remember it , but I think it''s a bunch of trigonomitry functions).
You'd have to use the sin() function and a cos() functions to figure it out. If you gave me a sample of the program, I could figure it out for you.

The functions are included in the Math.h header file, and yes, they are trigonometric (dealing w/ triangles).

*edit*
Actually, it all just depends on how you are rotating the screen. If the ship is rotating, then you'd use sin and cos, if your rotating the screen around the ship, then you'd have to use arcsin and arccos.

[edited by - KillerMonk on October 6, 2002 11:18:05 PM]
void move( vec2& pos, float speed, float angle )
{
vec2 temp;
temp.x = speed * cos( angle );
temp.y = speed * sin( angle );

pos += temp;
}

(bah, too lazy to register an account)

thanx alot il try that

This topic is closed to new replies.

Advertisement