Announcement
Collapse
No announcement yet.
RTS prototype
Collapse
X
-
Originally posted by Neongho View PostNice, i would love to see the AI code
Hey. I just followed the Mougli AI tutorial:
Code:class CMAIController extends AIController; var Vector TargetLocation; var Vector TempDest; event PostBeginPlay() { super.PostBeginPlay(); NavigationHandle = new(self) class'NavigationHandle'; } event Possess(Pawn inPawn, bool bVehicleTransition) { super.Possess(inPawn, bVehicleTransition); Pawn.SetMovementPhysics(); } function MoveToTarget(Vector v) { TargetLocation = v; TargetLocation.Z += Pawn.EyeHeight; GoToState('MoveToLocation'); } function float GetPathLength() { //TODO return 0; } state MoveToLocation { function bool FindNavMeshPath() { // Clear cache and constraints (ignore recycling for the moment) NavigationHandle.PathConstraintList = none; NavigationHandle.PathGoalList = none; // Create constraints class'NavMeshPath_Toward'.static.TowardPoint( NavigationHandle,TargetLocation ); class'NavMeshGoal_At'.static.AtLocation( NavigationHandle, TargetLocation,32 ); // Find path return NavigationHandle.FindPath(); } Begin: if( NavigationHandle.PointReachable(TargetLocation) ) { MoveToDirectNonPathPos(TargetLocation,None,32); GotoState('Idle'); } else if( FindNavMeshPath() ) { NavigationHandle.SetFinalDestination(TargetLocation); 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, None,32); } } else { GotoState('Idle'); } goto 'Begin'; } auto state Idle { Begin: } defaultproperties { }
Comment
Comment