Trace actions in a shooting situation

In this recipe we'll introduce the Trace action, which is very useful for testing whether the space between two actors is obstructed or unobstructed. The example we'll use continues from the last scene, where a wall drops down to reveal a Bot who wants to shoot at us. Being told to shoot at us, he does so regardless of the wall, which is not plausible, so adding the Trace will help with that.

Getting ready

Open Packt_04_SimpleTrace_Start.UDK or continue from where you were in the last recipe if you wish.

How to do it...

  1. Open Kismet and, following the existing Actor Factory that provisions and spawns an enemy Bot, right-click and choose New Action | Misc | Trace. A Trace action draws a line between a Start object and an End object. You can also specify an exact HitObject it is looking for but in this case we don't need to. That would be more likely if you wanted to check against a NPC rather just a wall, which is what's getting in the robot's firing line on the player.
  2. In the scene, select the Mover that is assigned to the Matinee action's Dropper nub (InterpActor_5) by right-clicking on the Object Variable and choosing Select InterpActor_5 in Level. Then right-click on the HitObject nub of the Trace action and choose New Object Var using InterpActor_5. Or you could just drag an additional wire to the existing variable. Also hook the Object Variable ???, which is the spawned Bot, to the Start nub and the Player Variable to the End nub, as seen in the following screenshot:
    How to do it...
  3. In the properties of the Trace, do not tick on the check box for Trace Actors. It will prevent the line of sight. Because the wall is a Mover, actually it is already part of the world and doesn't need to be set specifically set as an Object Variable under the HitObject Object nub of the Trace.
  4. What we need now is to provision the outputs for the Trace action. Not Obstructed fires off actions if the player is seen by the Bot. If the wall is still in the way, then the Obstructed nub fires off and it can be left empty, since nothing happens in that case. For the Not Obstructed nub, hook it up to the existing Start Firing At action, which harks back to the earlier recipe Creating a simple enemy Bot.
  5. At present the Trace will only fire off once. We need to make it loop, so the Bot is constantly checking whether it can see what it is supposed to shoot at. The sequence shown next is a suitable loop back, with two Trace actions occurring, one for the first case, and one for repeated tracing after that. You need this because the Obstructed nub, once firing has begun, should go to a Stop Firing action. But initially, it should just loop back on itself and check again for further obstruction, all this before any shooting has begun.
    How to do it...
  6. Some pillars are added to the level so the player can hide from the Bot once the wall has dropped. You can use this to test if the trace works when you PIE.

How it works

A Trace generates a ray between two points. You then set up the actions you want to occur when that ray is obstructed or not. We just set loops for the Bot to follow to decide whether to fire or not, then whether to continue firing or stop.

In the properties of the Trace there are Offset amounts you can set from the specified Start and End actors which can help control the ray that's cast. For example, part of the player model or Bot model (such as a swinging arm or gigantic weapon) might get in the way of the trace from the actor's pivot, so an offset slightly ahead of the character might work to prevent that.

You can also set a Trace Extent, which means that even if there's a direct line of sight between the two actors, if the distance or extent is too great then it will be discarded.

Tip

You might see a warning in the log when you kill the Bot about the Stop Firing action having no handler. This is because once the Bot is killed, there's no Target for the Stop Firing action to register to. This matters because of the 2 second Set Activate Delay on its In nub. It's like yelling stop shooting when there is no longer anyone around shooting. To fix this, instead feed the connections coming to the In of the Stop Firing action into a Delay action's Start nub. Feed the Delay action's Finished nub into the In of the Stop Firing action instead. From the Death event's Out nub, extend a connection to the Delay action's Stop nub. You should also do this with the Stop nubs of the two other Delay actions in this section. It cancels the loops around the Trace when the Bot Death event occurs.

You can view an example in Packt_04_SimpleTrace_DEMO.UDK. The Delay actions have been stopped there.

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

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