Archived

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

Acceleration and Velocity in space

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

Alright, I''m designing a space game. (the over head, kinda like astroids) For rotation i''m using: xVelocity = speed * sin(shipsAngle); yVelocity = speed * cos(shipsAngle); speed is a predefined variable. shipsAngle is obviously the angle the ship is flying at. Ok, so now to my question... how do i integrate acceleration into the ships movement. As I have it now, the ship will (when the forward arrow key is pressed) go at full speed with no acceleration. How do I add the acceleration value into my code? Thanks. Brent

Share this post


Link to post
Share on other sites
Let speed be a _real_ variable, not predefined. Then you change that variable when a key is pressed.


#define MAX_SPEED 20

game loop:
{
if (key_up)
{
if (++speed>MAX_SPEED) speed = MAX_SPEED
}
if (key_down)
{
if (--speed<0) speed = 0
}
move the ship, and do other stuff here
}


[edited by - nickm on June 5, 2002 2:42:59 AM]

Share this post


Link to post
Share on other sites
This is a simple way of doing it:

... calculate the current forces acting upon the ship, this includes thrust, solar wind, asteroids bouncing off you, whatever ...

velocity += force;

... if you want, clamp the velocity to a maximum. in space, there is no maximum speed, because there is no air resistance. bear in mind that players will want to limit their speed because if they go too fast, they won't be able to react to the asteroids. it makes sense, then, to clamp velocity on easier skill levels, but make the player manage their speed on harder skill levels ...

position += velocity;


[edited by - Mayrel on June 6, 2002 4:34:10 PM]

Share this post


Link to post
Share on other sites
One strategy I like to use is to constantly try to decelerate the craft, even though there is no friction.

If the deceleration is applied to the current velocity BEFORE the force is added and the velocity is clamped (Perhaps the deceleration causes the clamping), you''ll get an automatic tending towards your direction of travel and your sliding will slowly go away.

Share this post


Link to post
Share on other sites