Next: , Previous: , Up: AI   [Contents][Index]


2.5 Nav Module

Component: NavModule

This component implements Unity’s NavMesh directly, allowing AI to pathfind around easily. You need to bake a navigation mesh for your scene before it can work, otherwise you will get an error. Click Window -> Navigation to bake a navmesh.

To get started most effectively, we recommend adding some other AI components such as a Guard Module, Melee Module, or others depending on what you want to make. For example, to make a tank, first create an empty object, and parent a 3D model of a tank to it. Then, add a Guard Module, Nav Module to the base object. Finally, add a Turret Action to the turret itself, a Targeting Computer (so it can aim at moving rigidbodies correctly), and create an invisible trigger with a Targeting Sensor component that sends it’s target message to the turret. This creates a tank AI.

See https://youtu.be/ClrtITChqkA.

Field of NavModule: MessageManager.ManagedMessage stationNotFound

If no available station is found, should we send a message?

Field of NavModule: bool debug

Should we output useful information to the console?

Default value: false

Available Messages

Message on NavModule: StopNavigating ()

Tells the Nav Mesh Agent to stop immediately, but does not affect the Nav Module directly.

Message on NavModule: Stun (float)

Causes the agent to be unable to move for a set duration

Argument: Time in seconds that the agent should be unable to move

Message on NavModule: NavToNearest (string)

Finds the nearest object with a given tag, and if found navigates to it.

Argument: The tag of the object we wish to move towards

Message on NavModule: EnableAgent ()

Sets the Nav Mesh Agent attached to this object to be enabled, allowing it to control the object’s position.

Message on NavModule: DisableAgent ()

Sets the Nav Mesh Agent attached to this object to be disabled, so that it will not control the object’s position.

Message on NavModule: ToggleAgent ()

Swaps the current enabled state of the Nav Mesh Agent

Message on NavModule: FaceTarget ()

Causes the AI to always face it’s target, no matter what direction it’s moving in

Message on NavModule: FaceMoveDirection ()

Causes the AI to always face it’s move direction, no matter the direction of the target

Message on NavModule: GoToStation (string)

Causes the AI to find an available, unoccupied ’AIStation’ component on an object with the tag you supply, then goes to it if available.

Argument: The GameObject tag of the station type we wish to find for this AI

Field of NavModule: MessageManager.ManagedMessage stationNotFound

If no available station is found, should we send a message?

Field of NavModule: bool debug

Should we output useful information to the console?

Default value: false

Available Messages

Message on NavModule: StopNavigating ()

Tells the Nav Mesh Agent to stop immediately, but does not affect the Nav Module directly.

Message on NavModule: Stun (float)

Causes the agent to be unable to move for a set duration

Argument: Time in seconds that the agent should be unable to move

Message on NavModule: NavToNearest (string)

Finds the nearest object with a given tag, and if found navigates to it.

Argument: The tag of the object we wish to move towards

Message on NavModule: EnableAgent ()

Sets the Nav Mesh Agent attached to this object to be enabled, allowing it to control the object’s position.

Message on NavModule: DisableAgent ()

Sets the Nav Mesh Agent attached to this object to be disabled, so that it will not control the object’s position.

Message on NavModule: ToggleAgent ()

Swaps the current enabled state of the Nav Mesh Agent

Message on NavModule: FaceTarget ()

Causes the AI to always face it’s target, no matter what direction it’s moving in

Message on NavModule: FaceMoveDirection ()

Causes the AI to always face it’s move direction, no matter the direction of the target

Message on NavModule: GoToStation (string)

Causes the AI to find an available, unoccupied ’AIStation’ component on an object with the tag you supply, then goes to it if available.

Argument: The GameObject tag of the station type we wish to find for this AI


Next: , Previous: , Up: AI   [Contents][Index]