PDA

View Full Version : Velocity and rotation help



SacAche
01-19-2014, 07:41 AM
Hi everyone,

I'm making a clone of Asteroids for uni and I'm having trouble getting the movements of the ship to function correctly.

At the moment I have the ship moving and turning, the problem is when the ship turns the momentum of the ship goes with it instead of just pivoting on the spot.

Here is my code, any help would be appreciated!


void update(float dt)
{
g_time += dt;

float aspeed = PI * dt;

if(isKeyPressed('q'))
{
g_angle += aspeed;
}

if(isKeyPressed('e'))
{
g_angle -= aspeed;
}

float ca = cos(g_angle);
float sa = sin(g_angle);

g_shipTransform.x.x = ca;
g_shipTransform.x.y = sa;
g_shipTransform.y.x = -sa;
g_shipTransform.y.y = ca;


if(isKeyPressed('w'))
{
if(g_speed <= MAX_SPEED)
{
g_speed += 0.01f;
}

g_shipTransform.w += g_shipTransform.y * g_speed;

}else{
g_shipTransform.w += g_shipTransform.y * (g_speed *= FRICTION);
}

}