I have a turret that rotates to face the mouse. This is simple enough if I want the turret to just face that direction atan2 will do that. But, what I want it to rotate it slowly.
I have a bit of code that works almost, haha. It will turn the turret CW or CCW depending on where the mouse is. The problem is when it crosses the 0 angle threshold.
Say for example the turret is at 5 degrees and the mouse is at 355 degrees. The turret will turn CW 350 degrees even though it is longer. CCW is only 10 degrees away.
I need a way to calculate the shortest route and move CW or CCW base on the answer.
I have tried several things and can't get it working right. I can't even work out in my mind what I need :(
Here is the base code.
Thanks for any insight you can give.
CTP
I have a bit of code that works almost, haha. It will turn the turret CW or CCW depending on where the mouse is. The problem is when it crosses the 0 angle threshold.
Say for example the turret is at 5 degrees and the mouse is at 355 degrees. The turret will turn CW 350 degrees even though it is longer. CCW is only 10 degrees away.
I need a way to calculate the shortest route and move CW or CCW base on the answer.
I have tried several things and can't get it working right. I can't even work out in my mind what I need :(
Here is the base code.
;turn turrent ;find angle to turn to calc = 360-ATan2(tankx- MouseX() ,tanky-MouseY()) ;set angle to 0 to 359 If calc>359 Then calc=calc-359 If calc<0 Then calc = 359+calc ;figure out if turn CW or CCW, which is closer ;turrentangle compared to calc ;turn CW If calc > turrentangle Then turrentangle = turrentangle + turrentspeed ;turn CCW ElseIf calc < turrentangle Then turrentangle = turrentangle - turrentspeed EndIf
Thanks for any insight you can give.
CTP