Jump to content
  • Advertisement
Sign in to follow this  
Flawe

Acceleration and movement problem

This topic is 4912 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

I'm trying to make a game with a space ship that has the same physics as teh asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot

Share this post


Link to post
Share on other sites
Advertisement

if (vel_x*vel_x)+(vel_y*vel_y)>(maxspeed*maxspeed)
{
vel_x=vel_x*maxspeed/sqrt((vel_x*vel_x)+(vel_y*vel_y))
vel_y=vel_y*maxspeed/sqrt((vel_x*vel_x)+(vel_y*vel_y))
}

that way u "normalize" the velociti.. i think.. :P

is not the best... but i think it will work..

Share this post


Link to post
Share on other sites
Sign in to follow this  

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