Hi, I forgot to tell that ArcTan2 function returns values between -Pi and +Pi.

Normally radians are declared between 0 and 2*Pi.

So I guess you can fix your problem by adding Pi to your calculated angle.

Angle := ArcTan2(U[0] - T[0], U[2] - T[2]) + Pi;

If you don't do that, your comparence with ">" or "<" cannot work correctly.

By the way. Meanwhile I changed my code and apply a virtual segment to my turret. Having this I can calculate if the "targeting point" is on the left or the right side of my "line"using the following code:

[pascal]
function IsPointOnRightSide(const PointX,PointY,SegmentX1,SegmentY1,SegmentX2,Segmen tY2:TFloat):Boolean;
begin
Result := (((SegmentX2 - SegmentX1) * (PointY - SegmentY1)) < ((PointX - SegmentX1) * (SegmentY2 - SegmentY1)));
end;
[/pascal]

Then I can say:

[pascal]
if IsPointOnRightSide(TargetPosX,TargetPosY,TurretSeg mentX1,TurretSegmentY1,TurretSegmentX2,TurretSegme ntY2) then
SteerTurretRight
else
SteerTurretLeft;
[/pascal]

Hope this helps...


Greetings,
Dirk