This page describes how to integrate Gameware Navigation into your Lua gameplay code. You will learn how to add a navigation world, and spawn bots.
We provide a set of Lua scripts to start integrating Navigation in your runtime. These scripts are located in core/gwnav/lua/runtime and will therefore be available in your project.
The main component to integrate is the navigation world (requires navworld.lua).
From this object you will be able to:
In your level initialization create a NavWorld object:
function MyGame:init() self.navworld = NavWorld(world, level) end
With:
The navigation world must be updated each frame.
You can also set a camera to use for visual debugging. When you connect the Navigation Lab to the engine, its camera can then track the camera in the interactive engine.
function MyGame:update(dt) self.navworld:update(dt) self.navworld:visual_debug_camera(self.maincamera) end
To add NavData to a world:
function MyGame:init() local nav_data = self.navworld:add_navdata("levels/empty") end
To remove NavData from a world:
self.navworld:remove_navdata(nav_data)
In order to render the navigation mesh in the viewport, call:
self.navworld:debug_draw(gui, line_object)
You will need to pass an initalised Gui and LineObject to this function. You will also need to have added some NavData to the world.
function MyGame:shutdown() self.navworld:shutdown() end
To add a bot to a NavWorld:
local configuration = NavBotConfiguration() -- You can change any parameters of the configuration: configuration.height = 1.8 local navbot = self.navworld:init_bot_from_unit(unit, configuration)
To remove a bot from a NavWorld:
navbot:shutdown()
To create a Box Obstacle:
local box_obstacle = NavBoxObstacle(navworld, unit) box_obstacle:add_to_world() box_obstacle:remove_from_world() -- obstacles is not destroyed, just no longer present in world
navworld is the NavWorld you wish this obstacle to reside in. unit is the Unit you wish to associate a Box Obstacle with. It will be configured according to the following scriptdata:
To create a Cylinder Obstacle:
local cylinder_obstacle = NavCylinderObstacle(navworld, unit) cylinder_obstacle:add_to_world() cylinder_obstacle:remove_from_world() -- obstacles is not destroyed, just no longer present in world
navworld is the NavWorld you wish this obstacle to reside in. unit is the Unit you wish to associate a Cylinder Obstacle with. It will be configured according to the following scriptdata:
To destroy an Obstacle:
box_obstacle:shutdown() cylinder_obstacle:shutdown()