Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

_Rotation in Flash

This topic is 4786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

var nInter = setInterval(rotate, 100); var increase:Number = 5; function rotate():Void{ ym.text = _root._ymouse + ", " + _root._xmouse; myRadians = Math.atan2(_root._ymouse-tank._y, _root._xmouse-tank._x); myDegrees = Math.round((myRadians*180/Math.PI)); if(tank._rotation > myDegrees+90) { tank._rotation -= increase; } if(tank._rotation < myDegrees+90) { tank._rotation += increase; } } okay, basically it gets the slope of the mouse to the tank turret i made...but when the mouse is in the lower left quadrent it just moves in complete circles without stopping...besides the lower left quadrent it works fine. i know its somthing to do with my ifs but i dont know what!

Share this post


Link to post
Share on other sites
Advertisement
here is some code i found that does the same thing i need, but its obfuscated


protected void spinTank(int i, int j, int k, int l)
{
if(k == i && l == j)
return;
if(i > 0 && i < 17 && j > 0 && j < 17)
{
int i1 = i * 24 + 12;
int j1 = j * 16 + 8;
int k1 = k * 24 + 12;
int l1 = l * 16 + 8;
double d = Math.atan2(i1 - k1, l1 - j1);
d = (8D * (d + 3.1415926535897931D + 0.19634954084936207D)) / 3.1415926535897931D;
int i2 = (int)d % 16;
int j2 = zona[j].direction & 0xf;
if(j2 != i2)
{
if(j2 > i2)
{
if(j2 - i2 >= 8)
j2++;
else
j2--;
} else
if(i2 - j2 >= 8)
j2--;
else
j2++;
if(j2 >= 16)
j2 -= 16;
else
if(j2 < 0)
j2 += 16;
zona[j].direction = (byte)((zona[j].direction & 0xf0) + j2);
buildScreen = true;
}
}
}




the code there is java heres my code to repeat this in flash...



var nInter;
var ymouse:Number = 0;
var xmouse:Number = 0;
var singleclick:Number = 0;
_root.onMouseDown = function(){
ymouse = _root._ymouse;
xmouse = _root._xmouse;
if(singleclick === 0)
{
singleclick = 1;
nInter = setInterval(rotate, 20);
}
}
var increase:Number = 1;
function rotate():Void{
ym.text = ymouse + ", " + xmouse;
myRadians = Math.atan2(ymouse-tank._y, xmouse-tank._x);
myDegrees = Math.round((myRadians*180/Math.PI));
if(tank._rotation >= myDegrees+90)
{

tank._rotation -= increase;
}
if(tank._rotation <= myDegrees+90)
{

tank._rotation += increase;
}

if(tank._rotation == myDegrees+90)
{
singleclick = 0;
clearInterval(nInter);
}

}



only thing wrong with mine, is that when i click in the lower left qudrant it goes ALL the way around to the right to get to it, because after i rotate 180 degrees the rotation turns negative....any idea on how i can stop this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!