void update()
{
if (thrust)
{
dx += cos(angle*DEGTORAD)*.02;
dy += sin(angle*DEGTORAD)*.02;
}
else
{
dx*=0.99;
dy*=0.99;
}
int maxSpeed = 15;
float speed = sqrt(dx*dx+dy*dy);
if (speed>maxSpeed)
{
dx *= maxSpeed/speed;
dy *= maxSpeed/speed;
}
x+=dx;
y+=dy;
.
.
.
}
In the above code, why is maxSpeed being divided by the speed variable. I'm stumped.
Thank you,
Josheir
↧