Click to See Complete Forum and Search --> : Firing bullets from rotating ship???


martini1
April 12th, 2009, 10:08 AM
I'm trying to get bullets to fire from the ship in the direction it is rotated. I've tried using the following, but it keeps firing long, weird lines to the top left corner of the screen. I have to admit that triggonometry stuff is vague to me...any tips?

double bvx,bvy,bpx,bpy;
void Bullet::InitObject(void)
{
dAngle = pSpaceship->getShipsAngle();

bvx = 10 * sin(dAngle) + pSpaceship->getShipsVelocity().XValue;
bvy = 10 * cos(dAngle) + pSpaceship->getShipsVelocity().YValue;

bpx = pSpaceship->getShipsPosition().XValue;
bpy = pSpaceship->getShipsPosition().YValue;

v2dVelocity = Vector2D(bvx,bvy);
v2dPosition = Vector2D(bpx,bpy);
}
///////////////////////////////////////////////////////////////////////////

void Bullet::DrawObject(void) //Draw the bullet as per coordinates
{
bvx = 10 * sin(dAngle);
bvy = -10 * cos(dAngle);
v2dVelocity += Vector2D(bvx,bvy);

pTheDrawEngine->LockBackSurface(); //Lock back surface

pTheDrawEngine->DrawLine(v2dPosition, v2dVelocity,
MyDrawEngine::YELLOW32);

pTheDrawEngine->UnlockBackSurface();//Unlock back surface

}

S_M_A
April 13th, 2009, 08:36 AM
Without knowing what kind of coordinate system you use... Normally sin/cos maps on y/x like:

*
**
z * *
* * y = z * sin(v)
* v *
******
x = z * cos(v)Maybe you're mixing x & y up?