Making Bots follow a path

In this recipe we'll make Bots follow a patrol then, when they are shot, make them try and hide. This introduces some essential control for AI path following.

Getting ready

Open the map Packt_04_PathFollowing_Start.UDK. The lesson continues on from the previous one.

How to do it...

  1. Open the Sub-Sequence Enemies. Here add a New Action | AI | Move to Actor. A Move to Actor action is for getting the Target object (which must be a pawn's Object Variable) to make its way to another game object, which is a path goal such as a PathNode, a JumpPad, a Trigger, or even the player. Add the Named Variable Bot as the Target of the Move to Actor.
  2. In the scene, go to the Edit menu and choose Find Actors. From the list select Pathnode_0, Pathnode_7, Pathnode_1, and Pathnode_6. Press Go To.
  3. In Kismet, right-click on the Destination nub of the Move to Actor, and choose New Object Vars Using Pathnode... to add all four selected actors at once.
  4. For the Look At nub of the Move to Actor, assign the Player 0 Variable. This forces the Bot to look at the player while running around.
  5. Add another Move to Actor action, and assign the Named Variable Bot to the Target nub, and the Player 0 Variable to the Look At nub. This time, in the scene use the Edit | Find Actors command to Go To the actors Pathnode_2, Pathnode_3, Pathnode_4, and Pathnode_5. Assign these to the Destination nub.
  6. Now you need to add two Delay actions (hold D and click). Hook the Delay actions to the Move to Actor actions as shown next. Also, connect the Death event's Out nub to the Stop nub of the each Delay. This is necessary so that when the Bot dies, the looped patrol knows he's no longer running around.
    How to do it...
  7. We can add a variation to the behavior of the Bot, which is that when he is hurt he runs and hides. He's going to run to the closest JumpPad actor in the scene. These are navigation points even though they aren't PathNodes. Since they will rapidly ping him elsewhere they may give him a moment of respite. Anyway, to balance the gameplay it'll be good to heal him if he manages to reach one.
  8. To do this, right-click and choose Create New Sequence within the current Sub-Sequence Enemies. Call it HideIfHurt. Inside this, hold ] and click to add a Finish Sequence action, and create nodes as follows:
    How to do it...
  9. The Take Damage event needs its Min Damage Amount set to 1. Set its Damage Threshold to 1.
  10. The Move to Actor action needs its property Pick Closest ticked on.
  11. The Modify Health node must have its Target as the Named Variable Bot, so it heals him, and its Damage property set to 100, with the Heal checkbox ticked on.
  12. In the Sub-Sequence Enemies, hook the Out nub of the Sub-Sequence HideIfHurt to the Start nub of either Delay D1 or D2 in the Bot Patrols section. The Bot resumes patrol after he's fled from being hurt.
  13. A final step, but quite important now the enemies can move around, is that there's a chance that a Bot might pick up the discarded ShockRifle should the player die. This is a problem because the impact from this gun is sufficient to push the player out of the level. This could be fixed by putting an invisible collision ceiling over the level, but it can also be fixed by re-arming the Bot who picks it up straightaway with the LinkGun instead, since that gun doesn't have the same kick. The way to do this is to extend from the Bot Actor Factory a New Condition | Is Using Weapon, and from the Using It output of that, hook up a New Action | Pawn | Give Inventory. The Is Using Weapon should be set to look for the use of a UTWeap_ShockRifle, and the Give Inventory should be set to provide a UTWeap_LinkGun. Clear Existing and Force Replace should be ticked on.
    How to do it...

How it works

The recipe before this one set up the goal of shooting ten Bots. This was rather easy, but now the Bot can run around in the scene too, it is a lot more of a challenge. The simplest way to get the Bot running around is to use a New Action | AI | Move to Actor action. If the Bot moves between only two points, or follows a regular sequence, the action is quite easy to predict, so instead, in this example, we added four possible destination points for the Bot to try and reach. It would choose the closest based on its current location. We added to this the variation that if the Bot were to be shot he'd run off to a JumpPad to get some air and that would heal him. You may notice when you PIE that the Bot's patrol path also sends him running over the JumpPads anyway, but he's not healed if he steps on it 'accidentally'.

An example map is provided: Packt_04_PathFollowing_DEMO.UDK.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.50.206