a T-turn is really simple.
Basically, you can test to see if both left and right options are available to you and use some algorithm to choose between them.
Code:
if( testTileIsObstacle( currentAngle, currentspeed ) = false )
begin
end
else
begin
left := testTileIsObstacle( currentAngle - 90, currentspeed );
right := testTileIsObstacle( currentAngle + 90, currentspeed );
if (left and right) then
begin
if (random(10)>5) then
begin
direction :=-90;
end
else
begin
direction := 90;
end;
end;
if (left) then
begin
direction := -90;
end;
if (right) then
begin
direction := -90;
end;
if(left=false and right=false) then
begin
direction := 180;
end;
end;
something along those lines might help..
Or, if you don't want random, you can always have some controlling variable which alternates between left and right so one unit goes left the next goes right in the event of a T-Junction
This sort of logic is what Pac Man used. Only pacman included the player's location in relation to the monster to make them chase or run away.
Bookmarks