Home Unreal Engine

Basic AI

Hey Polycount!
This is my first post on the forums, so I hope you can help me out! :3

I have this AI, which is made on Mougli's Portfolio example.
It's supposed to follow me, even if it can't see me any more. The way it does this, is with path finding of course. However, in my test level where I made a little maze, the bot refused to follow me, when it was surrounded by walls. This upset me greatly, as it should be capable of finding my location, even if it can't see me any more.
Help? xD

Here is the code for both the Bot and AI Controller:

AI Controller
class HS_AIController_Basic 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:
}

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 stop here, or it turns into an infinite loop
		GotoState('Idle');
	}
	goto 'Begin';
}
DefaultProperties
{
}

Bot
class HS_Bot extends UDKPawn placeable;

event PostBeginPlay() {
	super.PostBeginPlay();
}

DefaultProperties
{
	Begin Object Name=CollisionCylinder
		CollisionHeight=+44.000000
	end object
	Begin Object class=SkeletalMeshComponent Name=HSPawnSkeletalMesh
		SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
		HiddenGame=FALSE
		HiddenEditor=FALSE
	end object
	Mesh=HSPawnSkeletalMesh
	Components.Add(HSPawnSkeletalMesh)
	ControllerClass=class'HSGame.HS_AIController_Basic'
	bJumpCapable=false
	bCanJump=false
	GroundSpeed=200.0
}

Replies

  • FlynT
    Options
    Offline / Send Message
    FlynT polycounter lvl 8
    Hey Vipar weclome on the forums :)
    I've used Mouglis AI code as a base for my little project which is hosted on googlecode, so feel free to check out my sources here. http://goo.gl/4rncM
    Take a look inside the EoSC_AIController.uc and inside the EoSC_AIPawn.uc. Both need little tweaks to work with your project but nothing dramatic if you need help let me know. But i have to mention im not a programmer ;) so expect code that may be unclean. But it works with the latest UDK and im constantly updating and expanding it.
  • vipar
    Options
    Offline / Send Message
    I had a look at your source, and compared it with mine.
    They are very similar indeed. I think the only major difference is the PostBeginPlay();

    However, the problem is still present.
    The Pawn actually only follows me SOME of the way, in my maze, before it stops and will only move a little if I am very close. Once it gets to the first corner in the maze, it refuse to take one step further, however it will go back again.
    I have made a little picture here, which I hope might help a bit with understanding the situation.

    pawn%20problem.PNG
  • vipar
    Options
    Offline / Send Message
    Hmm, no one able to help? :<
  • vipar
    Options
    Offline / Send Message
    Well, since there was no help to gain, I found it out myself, after much trial and error.

    The fix was, to place the Pylon in the middle of the maze, and then change it's properties. Uncheck the box that says Destination Only.
Sign In or Register to comment.