Game Development Reference
In-Depth Information
3. For the third one, navigate to
Scripts
|
LookBusy
|
HangAround
.
The AI will find a random target from the list of GameObjects with the correct tag,
NpcActivityTarget
, as we set in the
LookBusy
script. Then, it moves to that target
and hangs around for 2 to 4 seconds.
Setting up wandering characters with React
Finally, we will create the NPCs and assign a behavior. For this, you can use a char-
acter similar to the first, just a sphere stretch 2x tall, with a small cube on the front of
it so that we can see the direction it is facing. Add the
LookBusy
script to the NPC:
This is how the
LookBusy
script options look like.
Minimum Distance
is how far away you can be from the target and still be satisfied
that you reached it.
Short Wait Time
and
Long Wait Time
are time ranges (in
seconds) you hang around for, and
NpcActivityTarget
is the tag that the GameOb-
jects have to identify as targets.
Next, add
Nav Mesh Agent
to the NPC so that it can navigate around the level. Fin-
ally, add the
Reactor
script and set its
Reactable
property to
LookBusyReactable
,
which is the behavior tree we created earlier.
This completes all the steps needed to have NPC characters wander around in a
game using React. You should now be able to create as many characters as you like
and have them walk around a level.