I want the player to fire a bullet when the mouse is clicked.
I now used ApplyImpulse on my bullet body to fire it, but the problem is, when the mouse is close, the bullet goes slower then when the mouse is far away, the direction is right though.
So, i need to find a way to keep the speed of the bullet the same, but still firing towards the mouse, this is what i came up with for now
I now used ApplyImpulse on my bullet body to fire it, but the problem is, when the mouse is close, the bullet goes slower then when the mouse is far away, the direction is right though.
So, i need to find a way to keep the speed of the bullet the same, but still firing towards the mouse, this is what i came up with for now
Code:
var diffX:Number = stage.mouseX - (map2D.player.playerBox.x + map2D.x);
var diffY:Number = stage.mouseY - (map2D.player.playerBox.y + map2D.y);
var angle:Number = Math.atan2(diffY, diffX);
bulletBody.ApplyImpulse(new b2Vec2(diffX / MapBox2D.RATIO, diffY / MapBox2D.RATIO
var diffY:Number = stage.mouseY - (map2D.player.playerBox.y + map2D.y);
var angle:Number = Math.atan2(diffY, diffX);
bulletBody.ApplyImpulse(new b2Vec2(diffX / MapBox2D.RATIO, diffY / MapBox2D.RATIO