Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

NavigationObstacle3D

Inherits: Node3D < Node < Object

3D Obstacle used in navigation to constrain avoidance controlled agents outside or inside an area.

Description

3D Obstacle used in navigation to constrain avoidance controlled agents outside or inside an area. The obstacle needs a navigation map and outline vertices defined to work correctly.

If the obstacle’s vertices are winded in clockwise order, avoidance agents will be pushed in by the obstacle, otherwise, avoidance agents will be pushed out. Outlines must not cross or overlap.

Obstacles are not a replacement for a (re)baked navigation mesh. Obstacles don’t change the resulting path from the pathfinding, obstacles only affect the navigation avoidance agent movement by altering the suggested velocity of the avoidance agent.

Obstacles using vertices can warp to a new position but should not moved every frame as each move requires a rebuild of the avoidance map.

Tutorials

Properties

bool

avoidance_enabled

true

int

avoidance_layers

1

float

height

1.0

float

radius

0.0

bool

use_3d_avoidance

false

Vector3

velocity

Vector3(0, 0, 0)

PackedVector3Array

vertices

PackedVector3Array()

Methods

bool

get_avoidance_layer_value ( int layer_number ) const

RID

get_navigation_map ( ) const

RID

get_rid ( ) const

void

set_avoidance_layer_value ( int layer_number, bool value )

void

set_navigation_map ( RID navigation_map )


Property Descriptions

bool avoidance_enabled = true

  • void set_avoidance_enabled ( bool value )

  • bool get_avoidance_enabled ( )

If true the obstacle affects avoidance using agents.


int avoidance_layers = 1

  • void set_avoidance_layers ( int value )

  • int get_avoidance_layers ( )

A bitfield determining the avoidance layers for this obstacle. Agent’s with a matching bit on the their avoidance mask will avoid this obstacle.


float height = 1.0

  • void set_height ( float value )

  • float get_height ( )

Sets the obstacle height used in 2D avoidance. 2D avoidance using agent’s ignore obstacles that are below or above them.


float radius = 0.0

  • void set_radius ( float value )

  • float get_radius ( )

Sets the avoidance radius for the obstacle.


bool use_3d_avoidance = false

  • void set_use_3d_avoidance ( bool value )

  • bool get_use_3d_avoidance ( )

If true the obstacle affects 3D avoidance using agent’s with obstacle radius.

If false the obstacle affects 2D avoidance using agent’s with both obstacle vertices as well as obstacle radius.


Vector3 velocity = Vector3(0, 0, 0)

Sets the wanted velocity for the obstacle so other agent’s can better predict the obstacle if it is moved with a velocity regularly (every frame) instead of warped to a new position. Does only affect avoidance for the obstacles radius. Does nothing for the obstacles static vertices.


PackedVector3Array vertices = PackedVector3Array()

The outline vertices of the obstacle. If the vertices are winded in clockwise order agents will be pushed in by the obstacle, else they will be pushed out. Outlines can not be crossed or overlap. Should the vertices using obstacle be warped to a new position agent’s can not predict this movement and may get trapped inside the obstacle.


Method Descriptions

bool get_avoidance_layer_value ( int layer_number ) const

Returns whether or not the specified layer of the avoidance_layers bitmask is enabled, given a layer_number between 1 and 32.


RID get_navigation_map ( ) const

Returns the RID of the navigation map for this NavigationObstacle node. This function returns always the map set on the NavigationObstacle node and not the map of the abstract obstacle on the NavigationServer. If the obstacle map is changed directly with the NavigationServer API the NavigationObstacle node will not be aware of the map change. Use set_navigation_map to change the navigation map for the NavigationObstacle and also update the obstacle on the NavigationServer.


RID get_rid ( ) const

Returns the RID of this obstacle on the NavigationServer3D.


void set_avoidance_layer_value ( int layer_number, bool value )

Based on value, enables or disables the specified layer in the avoidance_layers bitmask, given a layer_number between 1 and 32.


void set_navigation_map ( RID navigation_map )

Sets the RID of the navigation map this NavigationObstacle node should use and also updates the obstacle on the NavigationServer.