Code:
class SandboxAIController extends AIController;
var Actor Target;
var() Vector TempDest;
event Possess(Pawn inPawn, bool bVehicleTransition)
{
super.Possess(inPawn, bVehicleTransition);
Pawn.SetMovementPhysics();
}
auto state Idle
{
event SeePlayer (Pawn Seen)
{
super.SeePlayer(Seen);
target = Seen;
GotoState('Follow');
}
Begin:
`log("ERROR");
}
state Follow
{
ignores SeePlayer;
function bool FindNavMeshPath()
{
// Clear cache and constraints (ignore recycling for the moment)
NavigationHandle.PathConstraintList = none;
NavigationHandle.PathGoalList = none;
// Create constraints
class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle,target );
class'NavMeshGoal_At'.static.AtActor( NavigationHandle, target,32 );
// Find path
return NavigationHandle.FindPath();
}
Begin:
if( NavigationHandle.ActorReachable( target) )
{
FlushPersistentDebugLines();
//Direct move
MoveToward( target,target );
}
else if( FindNavMeshPath() )
{
NavigationHandle.SetFinalDestination(target.Location);
FlushPersistentDebugLines();
NavigationHandle.DrawPathCache(,TRUE);
// move to the first node on the path
if( NavigationHandle.GetNextMoveLocation( TempDest, Pawn.GetCollisionRadius()) )
{
DrawDebugLine(Pawn.Location,TempDest,255,0,0,true);
DrawDebugSphere(TempDest,16,20,255,0,0,true);
MoveTo( TempDest, target );
}
}
else
{
//We can't follow, so get the hell out of this state, otherwise we'll enter an infinite loop.
GotoState('Idle');
}
goto 'Begin';
`log("ERROR");
}
state Shoot
{
function Aim()
{
local Rotator final_rot;
final_rot = Rotator(vect(0,0,1)); //Look straight up
Pawn.SetViewRotation(final_rot);
}
Begin:
Pawn.ZeroMovementVariables();
Sleep(1); //Give the pawn the time to stop.
Aim();
Pawn.StartFire(1);
Pawn.StopFire(1);
GotoState('Idle');
`log("ERROR");
}
simulated event GetPlayerViewPoint(out vector out_Location, out Rotator out_Rotation)
{
// AI does things from the Pawn
if (Pawn != None)
{
out_Location = Pawn.Location;
out_Rotation = Rotation; //That's what we've changed
}
else
{
Super.GetPlayerViewPoint(out_Location, out_Rotation);
}
`log("ERROR");
}
DefaultProperties
{
}
Bookmarks