movement

Started by
4 comments, last by samosa 21 years, 11 months ago
hey, i havent posted in a while (too much school) but ive been reading the NeHe tuts and i decided to "start" on making a GTA sort of game, no getting out of the car, just driving around, i have my car, that spins but i cant figure out how to make in drive forward in the direction it is sipinning i have searched the site for any info but i cant find any, im gonna continue to look for any info i can find, any help would be greatly appreciated, thanks ,Matt -= kill one your a murderer, kill thousands your a conquerer =-
-= kill one you're a murderer, kill thousands you're a conquerer =-
Advertisement
How are you storing the rotation? Are you using an angle? If so, you need to apply an identical transform to the forward vector, then simply add the forward vector times a scalar speed to your current position. Alternatively you could use a separate velocity vector (not necessarily the same as forward) which allows you to do things like skidding. Of course, since you are in 2D, you can forgoe the vector transform entirely and just use trig to update your position:

x += cos (angle) * speed;
y += sin (angle) * speed;

However, i think if you want something like GTA, you are going to need some physics modeling (velocity, collision and friction on 2 axels at least) or you are not going to get the same kind of motion as you do in GTA.
hey, thanks alot, that works, i am not using angles, im just making it rotate based on spin which is a GLfloat variable (ex 1.0f) it moves around, but it only occasionally moves in the direction its facing, how could i find the angle?

,Matt

-= kill one your a murderer, kill thousands your a conquerer =-
-= kill one you're a murderer, kill thousands you're a conquerer =-
I know www.gametutorials.com has a nice couple tutorials that are good for vector based movement I would look at those they''re in the opengl section I learned a lot from them.
quote:Original post by samosa
hey, thanks alot, that works, i am not using angles, im just making it rotate based on spin which is a GLfloat variable (ex 1.0f) it moves around, but it only occasionally moves in the direction its facing, how could i find the angle?


If you are using a GLfloat with glRotatef, you are indeed using an angle (which is actually specified in degrees and NOT in radians as the C++ cos and sin functions or MS sinf and cosf functions are). You need to convert from degrees to radians. 180 degrees equals PI radians (where PI is approximately 3.1415926). So to convert from degrees to radians you multiply:

AngleInRadians = AngleInDegrees * PI / 180;
THANK YOU SO MUCH, i have recovered from my early wound and am ready to fly, finally, thank you all for helping me

,Matt

-= kill one your a murderer, kill thousands your a conquerer =-
-= kill one you're a murderer, kill thousands you're a conquerer =-

This topic is closed to new replies.

Advertisement