Hey kirupa! Im making a game where the player follows the mouse and shoots towards it. But I realized the laser-thing didn
t seem to be coming straight from the player. So I added a line going strait up and down on the player movie clip, and it seems that the rotate code is slightly offset. Can you help?
stage.addEventListener(Event.ENTER_FRAME,moveball);
function moveball(event:Event):void
{
var theX:int = mouseX - map_mc.player_mc.x;
var theY:int = (mouseY - map_mc.player_mc.y) * -1;
var angle = Math.atan(theY/theX)/(Math.PI/180);
if (theX < 0)
{
angle += 180;
}
if (theX >= 0 && theY < 0)
{
angle += 360;
}
map_mc.player_mc.rotation = (angle*-1) + 90;
}