Original Post
Hi, im busy making a micro-machine style game and am a little confused on getting the velocity in both Y and X directions when the car is travelling at an angle... The car is made up of a series of Seven Sprites, pointing at certain angles... the current layout is S, SW, W, NW, N, NE, E, SE When a directional arrow (Left or right) is pressed then this angle is changed in the correct manner.. however my code for working out the velocity only sork correctly when the sprite is moving in the positive (S, SE, SW) direction, and whenever I try for the Negative Y-Direction it fails... I understand you have to perform the same calculation for the X Values just with Sin instead, but could you point me as to what I would need to do to get it to function correctly? Following this the YLocation is updated with I have left my friction calculation out until I get this sorted... Thanks in advance, Cyph [Edited by - cyph on July 25, 2005 7:44:04 AM]
// move forward
if(pTheInputEngine->KeyPressed(SDLK_UP))
{
// get correct angle (from the N direction is this the
// correct way to do it?!)
switch(spriteNumber)
{
case 0:
angle = 180;
break;
case 1:
angle = 135;
break;
case 2:
angle = 90;
break;
case 3:
angle = 45;
break;
case 4:
angle = 0;
break;
case 5:
angle = 45;
break;
case 6:
angle = 90;
break;
case 7:
angle = 135;
break;
default:
break;
}
// add accelleration (i cant spell ;))
YVelocity += (Accelleration * (pTheTimerEngine->GetFrameTime()/1000));
//Calculate Y-component of velocity...
YVelocity = - (YVelocity * cos(angle*PI/180));
}
YLocation += YVelocity;
worldYLocation += YVelocity;