I'm trying to create a simple topdown game, in which you control the player by WASD keys and use mouse to aim and shoot. So far, I have a player moving and firing, but I think there is something wrong with the shooting.
Accuracy gets lower as the mouse cursor move away from the player.
Please try the following SWF to see more clearly what I'm trying to say.
http://dl.dropbox.com/u/24777511/gdstack.swf
Here is a chunk of relevant code:
private function fireBullet(x:Number, y:Number, dFireAngle:Number):void {
var b:Bullet = recycleBullet();
var rFireAngle:Number;
b.reset(x, y);
b.angle = dFireAngle;
rFireAngle = (dFireAngle * (Math.PI / 180));
b.velocity.x = Math.cos(rFireAngle) * 385;
b.velocity.y = Math.sin(rFireAngle) * 385;
}
...
if (FlxG.mouse.pressed()) {
var p:FlxPoint = new FlxPoint(FlxG.mouse.screenX, FlxG.mouse.screenY);
var angle:Number = FlxU.getAngle(new FlxPoint(player.x, player.y), p) - 90;
fireBullet(player.x, player.y, angle);
...