Acceleration and Velocity in space

Started by
2 comments, last by so88ccer 21 years, 10 months ago
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
Advertisement
Let speed be a _real_ variable, not predefined. Then you change that variable when a key is pressed.

#define MAX_SPEED      20game 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]
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]
CoV
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.
It's not what you're taught, it's what you learn.

This topic is closed to new replies.

Advertisement