NavigationController ​
Inherits: NavigationAgent3D
The path-finding and movement of an NPC: a navigation agent that moves the entity to a position, follows a target, or takes direct movement input. It moves in one of five styles (normal, keep facing, backpedal, strafe left, strafe right) and emits path_failed, following_started, following_stopped and destination_reached.
Variables ​
Methods ​
void | initialize_navigation_controller( entity_ref: Entity ) |
void | set_direct_input_mode( enabled: bool ) |
void | set_direct_movement_input( input_vector: Vector2, movement_speed: float, entity_forward: Vector3 ) |
void | set_vertical_input( value: float ) |
bool | is_using_direct_input() |
Vector3 | get_direct_input_velocity() |
void | process_physics( delta: float ) |
Vector3 | get_steer_heading() |
bool | should_ignore_desired_distance_for_los() |
bool | command_move_to( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) |
bool | command_move_keep_facing( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) |
bool | command_backpedal_to( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) |
bool | command_strafe_to( target_pos: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 ) |
bool | command_follow( target: Node3D, min_distance: float = 2.0, should_walk: bool = false ) |
void | command_stop() |
void | command_look_at( look_at_direction: Vector3, speed: int = Entity.FaceTargetSpeed.INSTANT ) |
void | set_approach_distance( distance: float ) |
void | set_custom_gravity( new_gravity: float ) |
void | reset_custom_gravity() |
void | cleanup_timers() |
Signals ​
path_failed() ​
Emitted when there is no path to the target, or the entity could not get there in time.
stalled( seconds_in_a_row: int ) ​
The entity was stuck for a second (it moved less than a fifth of what its speed gives, away from its goal): the number of seconds in a row. Two helps are tried, then path_failed
following_started( target: Node3D ) ​
Emitted when the entity starts following a node.
following_stopped() ​
Emitted when the entity stops following.
destination_reached( position: Vector3 ) ​
Emitted when the entity reaches the position it was sent to.
Enumerations ​
enum MovementStyle ​
How the entity faces while it moves: normal (it faces where it goes), keep facing, backpedal, or strafe left or right.
- NORMAL =
0 - KEEP_FACING =
1 - BACKPEDAL =
2 - STRAFE_LEFT =
3
enum NavigationMode ​
What the controller is doing: stopped, moving to a position, following a target or pathfinding.
- STOPPED =
0 - MOVING_TO_POSITION =
1 - FOLLOWING_TARGET =
2 - PATHFINDING =
3
Constants ​
floatSWIM_WAYPOINT_DISTANCE =1.5- How near (metres across) a swimmer has to be to a point of its path before it heads for the next one. The agent counts the distance in 3D, and a swimmer is up at the surface while the path runs over the bed, so it would never get near enough: the swimmer keeps its own countfloatSTALL_WINDOW =1.0- The seconds between two looks at whether a moving entity has got anywhere, and how much of the distance its speed should have given it counts as having got nowherefloatSTALL_FRACTION =0.2intSTALL_TRIES =3- How many times of getting nowhere in the last STALL_MEMORY seconds are given a try at getting free (a new path, then the other way of swimming) before the move is given up (path_failed). Counted over a while and not in a row: the help makes the entity move, so a goal it can never reach would look free after every helpfloatSTALL_MEMORY =15.0
Variable descriptions ​
Entity entity = null ​
The entity this controller moves.
EntityStateComponent entity_states_component = null ​
The states component of the entity (movement states).
NavigationMode current_navigation_mode = NavigationMode.STOPPED ​
What the controller is doing now.
float desired_distance = 0.5 ​
How close to the target the entity gets before it counts as arrived.
bool force_walking = false ​
True when the entity walks and does not run.
bool follow_mode = false ​
True while the entity follows a node.
Node3D follow_target = null ​
The node the entity follows.
float follow_distance = 2.0 ​
How far from the followed node the entity stops.
MovementStyle current_movement_style = MovementStyle.NORMAL ​
The movement style of the current move.
float gravity = ProjectSettings.get_setting("physics/3d/default_gravity") ​
The gravity applied to the entity (the project's by default).
float falling_tolerance = 0.5 ​
How far the entity can drop before it counts as falling.
float velocity_smoothing = 3.0 # Lower = wider/smoother turns ​
How smooth the turns are: lower is wider and smoother.
float rotation_smoothing = 5.0 ​
Speed of rotation when following movement
float approach_slowdown_distance = 3.0 ​
The distance from the target where the entity starts to slow down.
float stopping_tolerance = 0.1 ​
The distance from the target where the entity stops.
float path_timeout_duration = 10.0 ​
The seconds the entity gets to reach the target before the path fails.
float path_timeout_extension_per_waypoint = 2.0 ​
The seconds added to the timeout for each waypoint of the path.
bool handling_waypoint = false ​
True while the entity handles a waypoint of its path.
bool direct_input_mode = false ​
True while the entity is moved by direct input (a player) and not by a path.
Vector3 direct_input_velocity = Vector3.ZERO ​
The velocity the direct input asks for.
float direct_input_speed = 5.0 ​
The speed of the direct input.
float vertical_input = 0.0 ​
The vertical input of the player in a free movement mode (1 up, -1 down)
bool steered_externally = false ​
A driver (the AI of a seat of a vehicle) moves the body: the navigation only says which way to go (get_steer_heading) and does not move it itself
Vector3 previous_position = Vector3.ZERO ​
Where the entity was on the last step (to see if it is stuck).
bool was_on_floor = true ​
True when the entity was on the floor on the last step.
bool direction_needs_update = false ​
True when the direction of the path must be worked out again.
int navigation_domain = EntityDefinition.NavigationDomain.AMPHIBIOUS ​
Where this entity can go (EntityDefinition.NavigationDomain): it picks the navigation map, and a water-only creature does not walk
Vector3 original_target_position = Vector3.ZERO ​
The position the entity was first sent to.
float current_speed = 5.0 ​
The speed of the entity now.
Vector3 movement_target = Vector3.ZERO ​
The position the entity is moving to now.
bool is_moving = false ​
True while the entity is moving.
Timer stall_check_timer ​
The timer that checks whether the entity is stuck.
Timer follow_update_timer ​
The timer that updates the path to a followed node.
Timer path_update_timer ​
The timer that updates the path.
Timer path_timeout_timer ​
The timer that fails the path when the entity takes too long.
Method descriptions ​
void initialize_navigation_controller( entity_ref: Entity ) ​
Sets the controller up for an entity.
void set_direct_input_mode( enabled: bool ) ​
Turns direct input on (a player moves it) or off (a path moves it).
void set_direct_movement_input( input_vector: Vector2, movement_speed: float, entity_forward: Vector3 ) ​
Gives the direct input: the stick or key vector, the speed and the forward direction of the entity.
void set_vertical_input( value: float ) ​
The vertical input in a free movement mode: 1 swims or flies up, -1 down, 0 neither (see MovementClaim). The controller of the player sets it every frame
bool is_using_direct_input() ​
Is the entity moved by direct input?
Vector3 get_direct_input_velocity() ​
The velocity the direct input asks for.
void process_physics( delta: float ) ​
Moves the entity one physics step (the path, the follow or the direct input).
Vector3 get_steer_heading() ​
The flat direction (a unit vector) the navigation wants to go in now: towards the next point of its path, or towards what it follows. Zero when it has nowhere to go. This is what a driver reads when it moves the body itself (steered_externally); reaching the end of the path stops the navigation as usual, so the behavior goes on
bool should_ignore_desired_distance_for_los() ​
Check if we should ignore desired distance due to LOS requirements
bool command_move_to( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​
Sends the entity to a position (it faces where it goes). A minimum distance stops it short. False when there is no path.
bool command_move_keep_facing( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​
Sends the entity to a position without turning to the direction of the movement.
bool command_backpedal_to( target_pos: Vector3, walk: bool = false, min_distance: float = -1.0 ) ​
Sends the entity to a position walking backward.
bool command_strafe_to( target_pos: Vector3, strafe_direction: int, walk: bool = false, min_distance: float = -1.0 ) ​
Sends the entity to a position sideways (a negative direction is left).
bool command_follow( target: Node3D, min_distance: float = 2.0, should_walk: bool = false ) ​
Makes the entity follow a node at a distance.
void command_stop() ​
Stops the entity.
void command_look_at( look_at_direction: Vector3, speed: int = Entity.FaceTargetSpeed.INSTANT ) ​
Turns the entity to a direction, at a speed (instantly by default).
void set_approach_distance( distance: float ) ​
Sets how close the entity gets to its target before it stops.
void set_custom_gravity( new_gravity: float ) ​
Set custom gravity value
void reset_custom_gravity() ​
Reset gravity to default project setting
void cleanup_timers() ​
Frees the timers of the controller.