appdeveloper
06-25-2009, 10:48 AM
Hi
I'm making a tank game.
In the game, i've made a function to rotate the tower of the tank. And this function is working:
private function move_Mouse():void
{
var n1:Number;
var n2:Number;
var radians = Math.atan2( mouseY -tower.y ,mouseX -tower.x);
var degrees = (radians / Math.PI) * 180;
tower.rotation = degrees-90;
}
but, now, i'm trying to rotate the soldiers in the game, acording to the tank position, which is not working, and i can't find out why:
private function enemies():void
{
var radians;
var degrees;
var counter:int;
for(counter=0;counter<m_totalSoldiers;counter++)
{
radians = Math.atan2(hero_base.y - bazucaMen[counter].y, hero_base.x - bazucaMen[counter].x);
degrees = (radians / Math.PI) * 180;
bazucaMen[counter].rotation = degrees ;
}
}
the bazucaMen[counter].rotation = degrees is not functioning, but if i do
bazucaMen[counter].rotation = bazucaMen[counter].rotation+degrees
then the soldiers just go crazy, rotating, even when the tank is stoped, which means this function is really getting called.
Any help?
My thanks in advanced
I'm making a tank game.
In the game, i've made a function to rotate the tower of the tank. And this function is working:
private function move_Mouse():void
{
var n1:Number;
var n2:Number;
var radians = Math.atan2( mouseY -tower.y ,mouseX -tower.x);
var degrees = (radians / Math.PI) * 180;
tower.rotation = degrees-90;
}
but, now, i'm trying to rotate the soldiers in the game, acording to the tank position, which is not working, and i can't find out why:
private function enemies():void
{
var radians;
var degrees;
var counter:int;
for(counter=0;counter<m_totalSoldiers;counter++)
{
radians = Math.atan2(hero_base.y - bazucaMen[counter].y, hero_base.x - bazucaMen[counter].x);
degrees = (radians / Math.PI) * 180;
bazucaMen[counter].rotation = degrees ;
}
}
the bazucaMen[counter].rotation = degrees is not functioning, but if i do
bazucaMen[counter].rotation = bazucaMen[counter].rotation+degrees
then the soldiers just go crazy, rotating, even when the tank is stoped, which means this function is really getting called.
Any help?
My thanks in advanced