I'm creating a bullet shooter much in the style of Touhou. Right now I want to have a very simple circular shot being fired from the enemy.
However, the spacing is very uneven, which isn't very good if you want to survive.
The code I'm using is this:
private function shoot() : void
{
const BULLETS_PER_WAVE : int = 72;
var interval : Number = BULLETS_PER_WAVE / 360;
for (var i : int = 0; i < BULLETS_PER_WAVE; ++i)
{
var xSpeed : Number = GameConstants.BULLET_NORMAL_SPEED_X * Math.sin(i * interval);
var ySpeed : Number = GameConstants.BULLET_NORMAL_SPEED_Y * Math.cos(i * interval);
BulletFactory.createNormalBullet(bulletColor_, alice_.center, xSpeed, ySpeed);
}
canShoot_ = false;
cooldownTimer_.start();
}
I imagine my mistake is in the sin
& cos
functions, but I'm not entirely sure what's wrong.
Answer
Golden rule when working with any kind of angle: Make sure you are using the correct unit. In this case, you should be using radians, not degrees.
Math.sin(i * interval * Math.PI / 180);
Math.cos(i * interval * Math.PI / 180);
If you want to fire bullets directly between boss and player, use atan2
, FYI.
No comments:
Post a Comment