🧭GridNav

Table to work with in-game navigation API.

CreateNpcMap(excluded_npcs [?]: CEntity[]|nil, includeTempTrees [?]: boolean): GridNavNpcMap

You should always call `GridNav.ReleaseNpcMap` after you done with your build pathing

Name
Type
Description

excluded_npcs [?]

table with npc to exclude from the map. for example you want to exclude local hero if you build path from local hero position (default: nil)

includeTempTrees [?]

boolean

true if you want include temp trees to the map e.g. furion's 1st spell, iron branch (default: true)

Creates a new GridNavNpcMap


ReleaseNpcMap(npc_map: GridNavNpcMap): nil

Name
Type
Description

npc_map

map to release to release

Releases allocated memory for GridNavNpcMap


IsTraversable(pos: Vector, flag [?]: number): boolean, integer

Name
Type
Description

pos

position to check

flag [?]

number

flag to check (default: 1)

Returns true if the world position is traversable.


BuildPath(start: Vector, end_: Vector, ignoreTrees [?]: boolean, npc_map [?]: GridNavNpcMap|nil): Vector[]

Name
Type
Description

start

position to start

end_

position to end

ignoreTrees [?]

boolean

true if you want to exclude static trees from the pathing (default: false)

npc_map [?]

map with the npc's positions which works as additional mask for terrain map (default: nil)

Build path from start to end. Returns an array with builded positions.

Example

-- build_path.lua
return {
    OnUpdate = function()
        local ignore_trees = false;
        local my_hero = Heroes.GetLocal();
        local start_pos = Entity.GetAbsOrigin(my_hero);
        local end_pos = Input.GetWorldCursorPos();

        -- create npc map with the temp trees but with no local hero in it
        local npc_map = GridNav.CreateNpcMap({Heroes.GetLocal()}, not ignore_trees);

        local path = GridNav.BuildPath(start_pos, end_pos, ignore_trees, npc_map);
        local prev_x, prev_y = nil, nil;
        for i, pos in pairs(path) do
            local x, y, visible = Renderer.WorldToScreen(pos);
            if (prev_x and visible) then
                Renderer.SetDrawColor(255, 255, 255, 255);
                Renderer.DrawLine(prev_x, prev_y, x, y);
            end
            prev_x, prev_y = x, y;
        end

        -- releasing allocated npc map after we done with build pathing
        GridNav.ReleaseNpcMap(npc_map)
    end
}

IsTraversableFromTo(start: Vector, end_: Vector, ignoreTrees [?]: boolean, npc_map [?]: GridNavNpcMap|nil): boolean

Name
Type
Description

start

position to start

end_

position to end

ignoreTrees [?]

boolean

true if you want to exclude static trees from the pathing (default: false)

npc_map [?]

map with the npc's positions which works as additional mask for terrain map (default: nil)

Lite version of GridNav.BuildPath function which just cheking if the path is exists.


DebugRender(grid_range [?]: integer, npc_map [?]: GridNavNpcMap|nil, render_cell_flags [?]: boolean): boolean

Name
Type
Description

grid_range [?]

integer

grid radius in "cell units" from Vector(0,0,0) (default: 50)

npc_map [?]

map with the npc's positions which works as additional mask for terrain map (default: nil)

render_cell_flags [?]

boolean

render the flags value for each not approachable cell (don't think you ever want to see this numbers, so ignore this arg) (default: false)

Debug render of current GridNav with GridNavNpcMap (if provided)

Last updated