NavigationServer3D
A server interface for low-level 3D navigation access.
NavigationServer3D.swift:33class NavigationServer3D
NavigationServer3D is the server that handles navigation maps, regions and agents. It does not handle A* navigation from AStar3D
.
Maps are made up of regions, which are made of navigation meshes. Together, they define the navigable areas in the 3D world.
For two regions to be connected to each other, they must share a similar edge. An edge is considered connected to another if both of its two vertices are at a distance less than edge_connection_margin
to the respective other edge’s vertex.
You may assign navigation layers to regions with regionSetNavigationLayers(region:navigationLayers:)
, which then can be checked upon when requesting a path with mapGetPath(map:origin:destination:optimize:navigationLayers:)
. This can be used to allow or deny certain areas for some objects.
To use the collision avoidance system, you may use agents. You can set an agent’s target velocity, then the servers will emit a callback with a modified velocity.
This server keeps tracks of any call and executes them during the sync phase. This means that you can request any change to the map, using any thread, without worrying.
This object emits the following signals:
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum ProcessInfo
class Signal1
Signal support.
Type members
static var shared: NavigationServer3D
The shared instance of this class
static func agentCreate(
) -> RID Creates the agent.
static func agentGetAvoidanceEnabled(agent: RID
) -> Bool Returns
true
if the providedagent
has avoidance enabled.static func agentGetMap(agent: RID
) -> RID Returns the navigation map
RID
the requestedagent
is currently assigned to.static func agentGetPaused(agent: RID
) -> Bool Returns
true
if the specifiedagent
is paused.static func agentGetUse3dAvoidance(agent: RID
) -> Bool Returns
true
if the providedagent
uses avoidance in 3D space Vector3(x,y,z) instead of horizontal 2D Vector2(x,y) / Vector3(x,0.0,z).static func agentIsMapChanged(agent: RID
) -> Bool Returns true if the map got changed the previous frame.
static func agentSetAvoidanceCallback(agent: RID, callback: Callable
) Sets the callback
Callable
that gets called after each avoidance processing step for theagent
. The calculatedsafe_velocity
will be dispatched with a signal to the object just before the physics calculations.static func agentSetAvoidanceEnabled(agent: RID, enabled: Bool
) If
enabled
istrue
, the providedagent
calculates avoidance.static func agentSetAvoidanceLayers(agent: RID, layers: UInt32
) Set the agent’s
avoidance_layers
bitmask.static func agentSetAvoidanceMask(agent: RID, mask: UInt32
) Set the agent’s
avoidance_mask
bitmask.static func agentSetAvoidancePriority(agent: RID, priority: Double
) Set the agent’s
avoidance_priority
with apriority
between 0.0 (lowest priority) to 1.0 (highest priority).static func agentSetHeight(agent: RID, height: Double
) Updates the provided
agent
height
.static func agentSetMap(agent: RID, map: RID
) Puts the agent in the map.
static func agentSetMaxNeighbors(agent: RID, count: Int32
) Sets the maximum number of other agents the agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
static func agentSetMaxSpeed(agent: RID, maxSpeed: Double
) Sets the maximum speed of the agent. Must be positive.
static func agentSetNeighborDistance(agent: RID, distance: Double
) Sets the maximum distance to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
static func agentSetPaused(agent: RID, paused: Bool
) If
paused
is true the specifiedagent
will not be processed, e.g. calculate avoidance velocities or receive avoidance callbacks.static func agentSetPosition(agent: RID, position: Vector3
) Sets the position of the agent in world space.
static func agentSetRadius(agent: RID, radius: Double
) Sets the radius of the agent.
static func agentSetTimeHorizonAgents(agent: RID, timeHorizon: Double
) The minimal amount of time for which the agent’s velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner this agent will respond to the presence of other agents, but the less freedom this agent has in choosing its velocities. A too high value will slow down agents movement considerably. Must be positive.
static func agentSetTimeHorizonObstacles(agent: RID, timeHorizon: Double
) The minimal amount of time for which the agent’s velocities that are computed by the simulation are safe with respect to static avoidance obstacles. The larger this number, the sooner this agent will respond to the presence of static avoidance obstacles, but the less freedom this agent has in choosing its velocities. A too high value will slow down agents movement considerably. Must be positive.
static func agentSetUse3dAvoidance(agent: RID, enabled: Bool
) Sets if the agent uses the 2D avoidance or the 3D avoidance while avoidance is enabled.
static func agentSetVelocity(agent: RID, velocity: Vector3
) Sets
velocity
as the new wanted velocity for the specifiedagent
. The avoidance simulation will try to fulfill this velocity if possible but will modify it to avoid collision with other agent’s and obstacles. When an agent is teleported to a new position useagentSetVelocityForced(agent:velocity:)
as well to reset the internal simulation velocity.static func agentSetVelocityForced(agent: RID, velocity: Vector3
) Replaces the internal velocity in the collision avoidance simulation with
velocity
for the specifiedagent
. When an agent is teleported to a new position this function should be used in the same frame. If called frequently this function can get agents stuck.static func bakeFromSourceGeometryData(navigationMesh: NavigationMesh?, sourceGeometryData: NavigationMeshSourceGeometryData3D?, callback: Callable
) Bakes the provided
navigationMesh
with the data from the providedsourceGeometryData
. After the process is finished the optionalcallback
will be called.static func bakeFromSourceGeometryDataAsync(navigationMesh: NavigationMesh?, sourceGeometryData: NavigationMeshSourceGeometryData3D?, callback: Callable
) Bakes the provided
navigationMesh
with the data from the providedsourceGeometryData
as an async task running on a background thread. After the process is finished the optionalcallback
will be called.static func freeRid(RID
) Destroys the given RID.
static func getDebugEnabled(
) -> Bool Returns
true
when the NavigationServer has debug enabled.static func getMaps(
) -> VariantCollection<RID> Returns all created navigation map
RID
s on the NavigationServer. This returns both 2D and 3D created navigation maps as there is technically no distinction between them.static func getProcessInfo(NavigationServer3D.ProcessInfo
) -> Int32 Returns information about the current state of the NavigationServer. See
ProcessInfo
for a list of available states.static func linkCreate(
) -> RID Create a new link between two positions on a map.
static func linkGetEnabled(link: RID
) -> Bool Returns
true
if the specifiedlink
is enabled.static func linkGetEndPosition(link: RID
) -> Vector3 Returns the ending position of this
link
.static func linkGetEnterCost(link: RID
) -> Double Returns the enter cost of this
link
.static func linkGetMap(link: RID
) -> RID Returns the navigation map
RID
the requestedlink
is currently assigned to.static func linkGetNavigationLayers(link: RID
) -> UInt32 Returns the navigation layers for this
link
.static func linkGetOwnerId(link: RID
) -> UInt Returns the
ObjectID
of the object which manages this link.static func linkGetStartPosition(link: RID
) -> Vector3 Returns the starting position of this
link
.static func linkGetTravelCost(link: RID
) -> Double Returns the travel cost of this
link
.static func linkIsBidirectional(link: RID
) -> Bool Returns whether this
link
can be travelled in both directions.static func linkSetBidirectional(link: RID, bidirectional: Bool
) Sets whether this
link
can be travelled in both directions.static func linkSetEnabled(link: RID, enabled: Bool
) If
enabled
istrue
, the specifiedlink
will contribute to its current navigation map.static func linkSetEndPosition(link: RID, position: Vector3
) Sets the exit position for the
link
.static func linkSetEnterCost(link: RID, enterCost: Double
) Sets the
enterCost
for thislink
.static func linkSetMap(link: RID, map: RID
) Sets the navigation map
RID
for the link.static func linkSetNavigationLayers(link: RID, navigationLayers: UInt32
) Set the links’s navigation layers. This allows selecting links from a path request (when using
mapGetPath(map:origin:destination:optimize:navigationLayers:)
).static func linkSetOwnerId(link: RID, ownerId: UInt
) Set the
ObjectID
of the object which manages this link.static func linkSetStartPosition(link: RID, position: Vector3
) Sets the entry position for this
link
.static func linkSetTravelCost(link: RID, travelCost: Double
) Sets the
travelCost
for thislink
.static func mapCreate(
) -> RID Create a new map.
static func mapForceUpdate(map: RID
) This function immediately forces synchronization of the specified navigation
map
RID
. By default navigation maps are only synchronized at the end of each physics frame. This function can be used to immediately (re)calculate all the navigation meshes and region connections of the navigation map. This makes it possible to query a navigation path for a changed map immediately and in the same frame (multiple times if needed).static func mapGetAgents(map: RID
) -> VariantCollection<RID> Returns all navigation agents
RID
s that are currently assigned to the requested navigationmap
.static func mapGetCellHeight(map: RID
) -> Double Returns the map cell height used to rasterize the navigation mesh vertices on the Y axis.
static func mapGetCellSize(map: RID
) -> Double Returns the map cell size used to rasterize the navigation mesh vertices on the XZ plane.
static func mapGetClosestPoint(map: RID, toPoint: Vector3
) -> Vector3 Returns the point closest to the provided
toPoint
on the navigation mesh surface.static func mapGetClosestPointNormal(map: RID, toPoint: Vector3
) -> Vector3 Returns the normal for the point returned by
mapGetClosestPoint(map:toPoint:)
.static func mapGetClosestPointOwner(map: RID, toPoint: Vector3
) -> RID Returns the owner region RID for the point returned by
mapGetClosestPoint(map:toPoint:)
.static func mapGetClosestPointToSegment(map: RID, start: Vector3, end: Vector3, useCollision: Bool
) -> Vector3 Returns the closest point between the navigation surface and the segment.
static func mapGetEdgeConnectionMargin(map: RID
) -> Double Returns the edge connection margin of the map. This distance is the minimum vertex distance needed to connect two edges from different regions.
static func mapGetLinkConnectionRadius(map: RID
) -> Double Returns the link connection radius of the map. This distance is the maximum range any link will search for navigation mesh polygons to connect to.
static func mapGetLinks(map: RID
) -> VariantCollection<RID> Returns all navigation link
RID
s that are currently assigned to the requested navigationmap
.static func mapGetObstacles(map: RID
) -> VariantCollection<RID> Returns all navigation obstacle
RID
s that are currently assigned to the requested navigationmap
.static func mapGetPath(map: RID, origin: Vector3, destination: Vector3, optimize: Bool, navigationLayers: UInt32
) -> PackedVector3Array Returns the navigation path to reach the destination from the origin.
navigationLayers
is a bitmask of all region navigation layers that are allowed to be in the path.static func mapGetRegions(map: RID
) -> VariantCollection<RID> Returns all navigation regions
RID
s that are currently assigned to the requested navigationmap
.static func mapGetUp(map: RID
) -> Vector3 Returns the map’s up direction.
static func mapGetUseEdgeConnections(map: RID
) -> Bool Returns true if the navigation
map
allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.static func mapIsActive(map: RID
) -> Bool Returns true if the map is active.
static func mapSetActive(map: RID, active: Bool
) Sets the map active.
static func mapSetCellHeight(map: RID, cellHeight: Double
) Sets the map cell height used to rasterize the navigation mesh vertices on the Y axis. Must match with the cell height of the used navigation meshes.
static func mapSetCellSize(map: RID, cellSize: Double
) Sets the map cell size used to rasterize the navigation mesh vertices on the XZ plane. Must match with the cell size of the used navigation meshes.
static func mapSetEdgeConnectionMargin(map: RID, margin: Double
) Set the map edge connection margin used to weld the compatible region edges.
static func mapSetLinkConnectionRadius(map: RID, radius: Double
) Set the map’s link connection radius used to connect links to navigation polygons.
static func mapSetUp(map: RID, up: Vector3
) Sets the map up direction.
static func mapSetUseEdgeConnections(map: RID, enabled: Bool
) Set the navigation
map
edge connection use. Ifenabled
istrue
, the navigation map allows navigation regions to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.static func obstacleCreate(
) -> RID Creates a new obstacle.
static func obstacleGetAvoidanceEnabled(obstacle: RID
) -> Bool Returns
true
if the providedobstacle
has avoidance enabled.static func obstacleGetMap(obstacle: RID
) -> RID Returns the navigation map
RID
the requestedobstacle
is currently assigned to.static func obstacleGetPaused(obstacle: RID
) -> Bool Returns
true
if the specifiedobstacle
is paused.static func obstacleGetUse3dAvoidance(obstacle: RID
) -> Bool Returns
true
if the providedobstacle
uses avoidance in 3D space Vector3(x,y,z) instead of horizontal 2D Vector2(x,y) / Vector3(x,0.0,z).static func obstacleSetAvoidanceEnabled(obstacle: RID, enabled: Bool
) If
enabled
istrue
, the providedobstacle
affects avoidance using agents.static func obstacleSetAvoidanceLayers(obstacle: RID, layers: UInt32
) Set the obstacles’s
avoidance_layers
bitmask.static func obstacleSetHeight(obstacle: RID, height: Double
) Sets the
height
for theobstacle
. In 3D agents will ignore obstacles that are above or below them while using 2D avoidance.static func obstacleSetMap(obstacle: RID, map: RID
) Assigns the
obstacle
to a navigation map.static func obstacleSetPaused(obstacle: RID, paused: Bool
) If
paused
is true the specifiedobstacle
will not be processed, e.g. affect avoidance velocities.static func obstacleSetPosition(obstacle: RID, position: Vector3
) Updates the
position
in world space for theobstacle
.static func obstacleSetRadius(obstacle: RID, radius: Double
) Sets the radius of the dynamic obstacle.
static func obstacleSetUse3dAvoidance(obstacle: RID, enabled: Bool
) Sets if the
obstacle
uses the 2D avoidance or the 3D avoidance while avoidance is enabled.static func obstacleSetVelocity(obstacle: RID, velocity: Vector3
) Sets
velocity
of the dynamicobstacle
. Allows other agents to better predict the movement of the dynamic obstacle. Only works in combination with the radius of the obstacle.static func obstacleSetVertices(obstacle: RID, vertices: PackedVector3Array
) Sets the outline vertices for the obstacle. If the vertices are winded in clockwise order agents will be pushed in by the obstacle, else they will be pushed out.
static func parseSourceGeometryData(navigationMesh: NavigationMesh?, sourceGeometryData: NavigationMeshSourceGeometryData3D?, rootNode: Node?, callback: Callable
) Parses the
SceneTree
for source geometry according to the properties ofnavigationMesh
. Updates the providedsourceGeometryData
resource with the resulting data. The resource can then be used to bake a navigation mesh withbakeFromSourceGeometryData(navigationMesh:sourceGeometryData:callback:)
. After the process is finished the optionalcallback
will be called.static func queryPath(parameters: NavigationPathQueryParameters3D?, result: NavigationPathQueryResult3D?
) Queries a path in a given navigation map. Start and target position and other parameters are defined through
NavigationPathQueryParameters3D
. Updates the providedNavigationPathQueryResult3D
result object with the path among other results requested by the query.static func regionBakeNavigationMesh(NavigationMesh?, rootNode: Node?
) Bakes the
navigationMesh
with bake source geometry collected starting from therootNode
.static func regionCreate(
) -> RID Creates a new region.
static func regionGetConnectionPathwayEnd(region: RID, connection: Int32
) -> Vector3 Returns the ending point of a connection door.
connection
is an index between 0 and the return value ofregionGetConnectionsCount(region:)
.static func regionGetConnectionPathwayStart(region: RID, connection: Int32
) -> Vector3 Returns the starting point of a connection door.
connection
is an index between 0 and the return value ofregionGetConnectionsCount(region:)
.static func regionGetConnectionsCount(region: RID
) -> Int32 Returns how many connections this
region
has with other regions in the map.static func regionGetEnabled(region: RID
) -> Bool Returns
true
if the specifiedregion
is enabled.static func regionGetEnterCost(region: RID
) -> Double Returns the enter cost of this
region
.static func regionGetMap(region: RID
) -> RID Returns the navigation map
RID
the requestedregion
is currently assigned to.static func regionGetNavigationLayers(region: RID
) -> UInt32 Returns the region’s navigation layers.
static func regionGetOwnerId(region: RID
) -> UInt Returns the
ObjectID
of the object which manages this region.static func regionGetTravelCost(region: RID
) -> Double Returns the travel cost of this
region
.static func regionGetUseEdgeConnections(region: RID
) -> Bool Returns true if the navigation
region
is set to use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.static func regionOwnsPoint(region: RID, point: Vector3
) -> Bool Returns
true
if the providedpoint
in world space is currently owned by the provided navigationregion
. Owned in this context means that one of the region’s navigation mesh polygon faces has a possible position at the closest distance to this point compared to all other navigation meshes from other navigation regions that are also registered on the navigation map of the provided region.static func regionSetEnabled(region: RID, enabled: Bool
) If
enabled
istrue
, the specifiedregion
will contribute to its current navigation map.static func regionSetEnterCost(region: RID, enterCost: Double
) Sets the
enterCost
for thisregion
.static func regionSetMap(region: RID, map: RID
) Sets the map for the region.
static func regionSetNavigationLayers(region: RID, navigationLayers: UInt32
) Set the region’s navigation layers. This allows selecting regions from a path request (when using
mapGetPath(map:origin:destination:optimize:navigationLayers:)
).static func regionSetNavigationMesh(region: RID, navigationMesh: NavigationMesh?
) Sets the navigation mesh for the region.
static func regionSetOwnerId(region: RID, ownerId: UInt
) Set the
ObjectID
of the object which manages this region.static func regionSetTransform(region: RID, transform: Transform3D
) Sets the global transformation for the region.
static func regionSetTravelCost(region: RID, travelCost: Double
) Sets the
travelCost
for thisregion
.static func regionSetUseEdgeConnections(region: RID, enabled: Bool
) If
enabled
istrue
, the navigationregion
will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.static func setActive(Bool
) Control activation of this server.
static func setDebugEnabled(Bool
) If
true
enables debug mode on the NavigationServer.class var godotClassName: StringName
Instance members
var avoidanceDebugChanged: SimpleSignal
Emitted when avoidance debug settings are changed. Only available in debug builds.
var mapChanged: Signal1
Emitted when a navigation map is updated, when a region moves or is modified.
var navigationDebugChanged: SimpleSignal
Emitted when navigation debug settings are changed. Only available in debug builds.