Skip to main content
GameDev.net gamedev.net
🔒 Locked

Easy math question...

Started by Dookie Jul 16, 2004 at 2:53 PM 3 replies 550+ views
Original Post
Dookie
Dookie
Hey guys. I'm trying to figure out a math problem for my 2D game, but for some reason I'm drawing a blank (not to mention I didn't make a very good grade in geometry class...) I have these: ship_maxVelocity (the fastest this ship will travel) ship_angle (rotational value in radians) ship_velocity[0] (velocity along the 'x' axis, between 'ship_maxVelocity * -1' and 'ship_maxVelocity') ship_velocity[1] (velocity along the 'y' axis, between 'ship_maxVelocity * -1' and 'ship_maxVelocity') And I want to use those to create a single, floating-point forward velocity value that's between ship_maxVelocity * -1 and ship_maxVelocity In other words, if I'm flying backwards in any direction and 'ship_maxVelocity' = 250, then my forward velocity value should be (-250). But if I'm flying forwards in any direction and 'ship_maxVelocity' = 250, then my forward velocity value should be 250. On the same note, if I'm flying sideways then my forward velocity value should be around zero. How should I create my equasion? I'm stumped! Thanks in advance for the help!
"The crows seemed to be calling his name, thought Caw"
ninmonkey
ninmonkey
Have you heard of Vectors? (not the container) I think it's exactly what you want.
--monkey
Dookie
Dookie
The values I've posted ARE vectors (of a rather large magnitude). What sort of vectors are you talking about and, more importantly, how can I get them to do what I want?

Remember, I don't have a whole lot of math background, so you may have to simplify ('dumb it down') what you're talking about.

Thanks!
"The crows seemed to be calling his name, thought Caw"
Zakwayda
Zakwayda
I'm not sure if I understood all that, but...

If ship_velocity.x and y can both be in the range -maxVel, maxVel, your actual velocity can exceed maxVel. I don't know if that's what you want.

So are you just looking for the magnitude of the velocity vector? If so, that would be sqrt(vel.x * vel.x + vel.y * vel.y).

I think what you really want is a unit length direction vector which would be something like [cos(angle), sin(angle)]. Then you would multiply this by a ship_speed variable to get your change in position.
Dookie
Dookie
I just figured it out... It would have been easier if I knew how the original programmer had performed his rotation calculations in the first place (it made it hard to get a radian value that I could make a comparison with), but I finally got a function working that gets the values I desire. Pretty cool!

Thanks for the help though. I appreciate it! Maybe I'll have a tougher question in the near future. ;)
"The crows seemed to be calling his name, thought Caw"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.