This content has been marked as final.
Show 6 replies

1. Re: Shooting a bullet.
crazygringo Sep 9, 2007 6:22 PM (in response to Donjworks)The math is a little tricky.
You need to convert the bullet vector into its angle using the Math.atan2 function.
Then you need to use the Math.cos and Math.sin functions to convert the vector into the x and y distances the bullet will travel (multiplied by your desired velocity).
This is the only way to make sure the bullet travels at a constant speed at any angle. 
2. Re: Shooting a bullet.
Donjworks Sep 10, 2007 4:05 AM (in response to Donjworks)Thanks... I knew it shouldn't have been that straight forward.... 
3. Re: Shooting a bullet.
Donjworks Sep 10, 2007 2:31 PM (in response to Donjworks)OK... I've completly rewritten the script, after reading about sine and cosine... sadly we learn that next term in math :(... anywho, here's my new code:

xspeed = Math.cos(dude._rotation)
yspeed = Math.sin(dude._rotation)
if (Key.isDown(key.SPACE)) {
b1._x = b1._x + xspeed
b1._y = b1._y + yspeed
}

b1  bullet
dude  the shooter
Now, it shoots in a nearly random direction... help? 
4. Re: Shooting a bullet.
kglad Sep 10, 2007 3:01 PM (in response to Donjworks)you must convert your _rotation (degrees) to radians. ie, use:

5. Re: Shooting a bullet.
Donjworks Sep 10, 2007 3:07 PM (in response to Donjworks)Thanks a ton kglad... it works.... 