hi all, not sure if this is the right place to ask this, but I've seen a share of good programmers around here (not to mention the man himself):
So I'm trying to make a turret (for a project) point towards the mouse, much like how sf does, and give the turret limited speed (so it doesn't simply snap to the mouse, again much like sf)
Current code determines the rotation the turret wants to be at as a function of mouse position and turret position:
Spoiler
return(Math.atan2((stage.mouseY-this.y),(stage.mouseX-this.x))*180/Math.PI);
and rotates the turret by increments to either side depending on if its rotation is greater than or smaller than the desired rotation
Spoiler
if (rotation - desired > rotationspeed* -1 && rotation - desired < rotationspeed)
{
return desired;
}
else if (desired > rotation)
{
return rotation + rotationspeed;
}
else if (desired < rotation)
{
return rotation - rotationspeed;
}
More or less does what I want. However, when the mouse is at the back of the turret, the desired rotation snaps from -180 to +180 and the turret goes all the way around to the mouse, and then around again if the mouse crosses the line again.
if you set the firing arc to 360 on a sf turret that won't be a problem, so there is a way around that. Wondering if anyone here knows this way and is willing to share it.
thanks in advance
gunny