• Advertisement
Sign in to follow this  

_Rotation in Flash

This topic is 4486 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
www.gotcha.playbf.com/turretmove.html


there you go...check that out and you will see what i mean i dont under stand! the other three quadrants work!

Share this post


Link to post
Share on other sites
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
why is it that i only get replies when i put an asshole remark lmao, maybe i need to start being a dick head to evry one and i might get some post on the topic

Share this post


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

  • Advertisement