Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For school I need to make a little game with UDK, the concept of the game is:

The player is the headguard, he will have some other guard (bots) who will follow him. Between the other guards and the player are some prisoners who need to evade the other guards.

It needs to look like thisenter image description here

My idea was to let the guard bots follow the player at a certain distance and let the prisoners bots in the middle try to evade the guard bots. Now is the problem i'm new to Unreal Script and the school doesn't support me that well.

Untill now I have only was able to make the guard bots follow me. I hope you guys can help me or make me something that will make this game work.

Here is the class i'm using to let te bots follow me:

class ChaseControllerAI extends AIController;

var Pawn player;
var float minimalDistance;
var float speed;
var float distanceToPlayer;
var vector selfToPlayer;

auto state Idle
    function BeginState(Name PreviousStateName)


    event SeePlayer(Pawn p)

        player = p;

       player = none;
       self.Pawn.Velocity.x = 0.0;
       self.Pawn.Velocity.Y = 0.0;
       self.Pawn.Velocity.Z = 0.0;
state Chase
    function BeginState(Name PreviousStateName)

    event PlayerOutOfReach()
        `Log("ChaseControllerAI CHASE Player out of reach.");

//  class ChaseController extends AIController; CONTINUED
// State Chase (continued)
    event Tick(float deltaTime)
       `Log("ChaseControllerAI in Event Tick.");

       selfToPlayer =  self.player.Location - self.Pawn.Location;
       distanceToPlayer = Abs(VSize(selfToPlayer));

       if (distanceToPlayer > minimalDistance)
          self.Pawn.Velocity = Normal(selfToPlayer) * speed;
          //self.Pawn.Acceleration =    Normal(selfToPlayer) * speed;
          self.Pawn.Move(self.Pawn.Velocity*0.001); // or *deltaTime
     `Log("Current state Chase:Begin: " @GetStateName()@"");

    bIsPlayer= true;
    minimalDistance = 1024; //org 1024
    speed = 500;
share|improve this question

migrated from Jan 13 '12 at 16:53

This question came from our site for professional and enthusiast programmers.

Have you looked into something like steering behaviors at all? There are some relatively simple things you can do like for seeking points and fleeing from points that might be relevant: – Tetrad Jan 13 '12 at 16:58
Can you give us one atomic thing that you would like to accomplish but haven't? "I would like to make the prisoners attempt to escape from the guards when they see x kind of opportunity." Something like that? – user9485 Mar 12 '12 at 22:43
"self.Pawn.Velocity = Normal(selfToPlayer) * speed;" is this the pawns moving directly towards the player? that would let the prisioners escape. Is best if pawns move to some desired location that is positioned relative to other point, and make that point the same for all paws. Possible make that point the "center of mass" of all prisioners. You can also make so the "desire to move near this point" is limited by the distance from pawn to pawn. If the distance from pawn to pawn is bigger than the prisioner size, the pawns will want to move to the center.. – Tei Apr 27 '12 at 13:01
What you are doing here is similar to a wolfpack hunting. – Tei Apr 27 '12 at 13:02

Assuming that the idea is that prisoners want to escape the circle of guards, trying to avoid them, what you could try is to apply something like the potential fields approach: With potential fields, guards will apply a repulsive force to the prisoners that come too close to them, and this will change the path prisoners will try to follow, apparently trying to stay away from them. I suppose prisoners will try to move to a position outside the circle of guards: in a simple way, if your prisoner is moving in the direction of a point outside the circle, at each update (or less frequently) you can check if it is close enough (sees) to any guard, and in the update do:

self.Velocity = Normal(self.Velocity) * speed;

// distance is the distance between this Prisoner and the closest Guards,
// minDistance is the distance at which if
if (distance < minDistance)
    vector rp = Normal(guard.RepulsiveForce) * (minDistance / distance);
    self.Velocity += rp;

Of course the Guard class needs a RepulsiveForce vector that will indicate the direction to which he will try to push close Prisoners: this vector will modify the current velocities of Prisoners that get close enough, and they will look like they will try to avoid them. But again, what you should also do is running a path planning algorithm (like A* star) for the prisoners to find a path and, while running the A*, treat the Guards (probably with a bigger influence circle) as obstacles.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.