AI

AI

Navigation

Navigation Area

In Lumberyard, we should set up the navigation area first to make sure in this certain area AI can move around. This can be setup in RollupBar window.

Navigation component

This window can help us to define where is walkable where is not. This area is a 3-dimensioned area which is a little bit different from Unity.

The default choice is the area walkable, we can also select “exclusion” to exclude the area we don’t want. The final navigation area will be like this:

Navigation area

The blue frame means walkable, the red frame means not walkable.

In Lumberyard 1.13, Navarea can also be added through a component: Navigation Area.

This component needs a polygon shape to define the navarea shape

Agent

AI needs a Navigation component. In which we can define some details of the agent.

Navigation component

AI also needs a Character Physics component to make it navigate using animations.

Script

In scripts, we need the navigationComponentNotificationBus to handle the navigation events. Here is an example:

function NavigationExample: OnActivate()
-- Tell the navigation component to start navigating.
self.navHandler = NavigationComponentNotificationBus.Connect(self, self.entityId)
-- Navigate to the first way point in the array
NavigationComponentRequestBus.Event.FindPathToEntity(self.entityId, self.Properties.wayPoint[0])
end

There are two functions it provides:

function NavigationExample:OnTraversalStarted(requestId)
end

function NavigationExample:OnTraversalComplete(requestId)
end

And we can use

NavigationComponentRequestBus.Event.FindPathToEntity(self.entityId,wayPoint);

to navigate the agent to a destination

In this way, we can add different way points to make the patrolling navigation happen.

Example code can be accessed here:  NavigationExample

State Machine

Example code ai_control.lua can be accessed here: AI_Example

This is an example of how to change between two states according to certain checks and how to make reactions after state changing.

Resources

Sidebar