04-11-2005, 01:02 PM
Quote:Then I have no idea what is wrong below...
The compiler says that it found ".sX" when it expected "=".
Code:With Bullet(UBound(Bullet))
'Initial coordinates of the bullet
.sX = Ship.sX
.sY = Ship.sY
.iAlive = 1
'Add the bullet and ship vectors, calculate resultant vector components
sXComp = Ship.sSpeed * Sin(Ship.sHeading) + BULLET_SPEED * Sin(Ship.sFacing)
sYComp = Ship.sSpeed * Cos(Ship.sHeading) + BULLET_SPEED * Cos(Ship.sFacing)
'Calculate speed using with |ai + bj| = Sqr (a^2 + b^2)
.sSpeed = Sqr(sXComp ^ 2 + sYComp ^ 2)
'Calculate the resultant heading
If sYComp > 0 Then .sHeading = Atn(sXComp / sYComp)
If sYComp < 0 Then .sHeading = Atn(sXComp / sYComp) + PI
End With
Unecesary ATN here.
Code:
.speed = length of vector
you could just normalize your vector ala:
Code:
nx! = sxcomp/.sspeed
ny! = sycomp/.sspeed
Or, instead of using ATN and checking which quadrant your vector points to, you could just use atan2.
.sHeading = atan2(sYComp, sxComp)
But I would not combine both processes to do bullets. Either use sqr or atan2.