Jump to content
  • Advertisement
Sign in to follow this  

Spaceship steering.

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

Hello. Im trying to create a cool steering for my spaceship dogfighting game. The problem is i it was very long ago i studied physics in school. I remember basic stuff like acceleration and forces. But how do you make it fun and cool? Hmm :-) As it is now its really only a freelook camera with dampening on, which is the results of my sorry attempts. Does anyone know a good resource/(open source game) for making a fun way of controlling a spaceship in fast paced battle? I am looking for stuff like taking the ships roll into accout when going forward to produce a turn, or looping, etc. It dosn't have to be realistic, as long as its fun. This stuff was harder than i tought to do. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
here is in essence the source code.



Vector xShipPos(0, 0, 0);
Vector xShipSide(-1, 0, 0);
Vector xShipUp(0, 1, 0);
Vector xShipDir(0, 0, 1);
float fShipSpeed = 0.0f;;
float fShipPitch = 0.0f;
float fShipYaw = 0.0f;
float fShipRoll = 0.0f;


void ShipMove(float dt)
{
xShipPos += xShipDir * fShipSpeed * dt;

if (xShipPos.y < 10.0f)
xShipPos.y = 10.0f;

if (xShipPos.y > 1000.0f)
xShipPos.y = 1000.0f;
}

void ShipPitch(float dt)
{
Quaternion Q;
Q.FromRotation(xShipSide, fShipPitch * dt);

xShipUp = xShipUp * Q;
xShipDir = xShipDir * Q;
}

void ShipYaw(float dt)
{
Quaternion Q;
Q.FromRotation(xShipUp, fShipYaw * dt);

xShipSide = xShipSide * Q;
xShipDir = xShipDir * Q;
}

void ShipRoll(float dt)
{
Quaternion Q;
Q.FromRotation(xShipDir, fShipRoll * dt);

xShipSide = xShipSide * Q;
xShipUp = xShipUp * Q;
}

void ShipUpdate(float dt)
{
xShipSide = xShipUp.Cross(xShipDir);

float fAccel = KeyPressed('W') - KeyPressed('S');
float fPitch = (mousey - 0.5f) * 2.0f;
float fYaw = KeyPressed('A') - KeyPressed('D');
float fRoll = (mousex - 0.5f) * 2.0f;

fShipSpeed = Clamp(fShipSpeed + fAccel * 0.04f, -20.0f, 20.0f);
fShipPitch = fPitch * 0.4f;
fShipYaw = fYaw * 0.2f;
fShipRoll = fRoll * 0.6f;

ShipPitch(dt);
ShipYaw (dt);
ShipRoll (dt);
ShipMove (dt);

xShipUp.Normalise();
xShipSide = xShipUp.Cross(xShipDir);
xShipSide.Normalise();
xShipDir = xShipSide.Cross(xShipUp);
xShipDir.Normalise();
}



I think it's self explanatory. It just takes a set of inputs and converts it into orientations and accelerations.

you can find the full demo here.

keys are mouse, and a, w, s, d.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!