Collision detection when pathfinding with pathnodes, UDK
- by Dave Voyles
I'm trying to create a class that allows my AIController to path find using pathnodes (NOT NavMeshes).
It's doing a swell job of going from point to point in a set order (although I would like for it to be a random patrol at some point), but it gets caught up on collision from time to time. I.E. He'll walk the same set path, and when he runs into the blocks in the middle of the map he continues to rub against them until they finish, and continues on his merry way to the next path node.
How can I prevent this from happening, or at least have him move from the wall if he does a trace and detects that it is there?
It looks like I need to use MoveToward() instead of MoveTo(), as MoveToward allows the pawn to adjust its course during movement. I'm just not sure of how to use those paramters.
Mougli has a decent tutorial on it[/URL], but I can't seem to get it to work correctly with my pathnode array.
class PathfindingAIController extends UDKBot;
var array Waypoints;
var int _PathNode; //declare it at the start so you can use it throughout the script
var int CloseEnough;
simulated function PostBeginPlay()
{
local PathNode Current;
super.PostBeginPlay();
//add the pathnodes to the array
foreach WorldInfo.AllActors(class'Pathnode',Current)
{
Waypoints.AddItem( Current );
}
}
simulated function Tick(float DeltaTime)
{
local int Distance;
local Rotator DesiredRotation;
super.Tick(DeltaTime);
if (Pawn != None)
{
// Smoothly rotate the pawn towards the focal point
DesiredRotation = Rotator(GetFocalPoint() - Pawn.Location);
Pawn.FaceRotation(RLerp(Pawn.Rotation, DesiredRotation, 3.125f * DeltaTime, true), DeltaTime);
}
Distance = VSize2D(Pawn.Location - Waypoints[_PathNode].Location);
if (Distance <= CloseEnough)
{
_PathNode++;
}
if (_PathNode >= Waypoints.Length)
{
_PathNode = 0;
}
GoToState('Pathfinding');
}
auto state Pathfinding
{
Begin:
if (Waypoints[_PathNode] != None) // make sure there is a pathnode to move to
{
MoveTo(Waypoints[_PathNode].Location); //move to it
`log("STATE: Pathfinding");
}
}
DefaultProperties
{
CloseEnough=400
bIsplayer = True
}