2020-01-10 19:22:34 +08:00
|
|
|
/*************************************************************************/
|
2020-03-27 05:49:16 +08:00
|
|
|
/* navigation_agent_3d.h */
|
2020-01-10 19:22:34 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-04 04:27:34 +08:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-01-10 19:22:34 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#ifndef NAVIGATION_AGENT_3D_H
|
|
|
|
#define NAVIGATION_AGENT_3D_H
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
#include "scene/main/node.h"
|
2022-10-06 07:24:45 +08:00
|
|
|
#include "servers/navigation/navigation_path_query_parameters_3d.h"
|
|
|
|
#include "servers/navigation/navigation_path_query_result_3d.h"
|
2020-01-10 19:22:34 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
class Node3D;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
class NavigationAgent3D : public Node {
|
|
|
|
GDCLASS(NavigationAgent3D, Node);
|
2020-01-10 19:22:34 +08:00
|
|
|
|
2020-05-12 23:01:17 +08:00
|
|
|
Node3D *agent_parent = nullptr;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
RID agent;
|
2022-05-18 02:08:39 +08:00
|
|
|
RID map_before_pause;
|
2022-06-15 02:39:15 +08:00
|
|
|
RID map_override;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
2022-05-21 04:55:27 +08:00
|
|
|
bool avoidance_enabled = false;
|
2022-06-15 05:34:43 +08:00
|
|
|
uint32_t navigation_layers = 1;
|
2022-10-06 07:24:45 +08:00
|
|
|
BitField<NavigationPathQueryParameters3D::PathMetadataFlags> path_metadata_flags = NavigationPathQueryParameters3D::PathMetadataFlags::PATH_METADATA_INCLUDE_ALL;
|
2022-03-20 04:47:02 +08:00
|
|
|
|
2022-06-19 01:11:49 +08:00
|
|
|
real_t path_desired_distance = 1.0;
|
2020-05-12 23:01:17 +08:00
|
|
|
real_t target_desired_distance = 1.0;
|
2022-05-02 22:28:25 +08:00
|
|
|
real_t radius = 0.0;
|
2020-05-12 23:01:17 +08:00
|
|
|
real_t navigation_height_offset = 0.0;
|
2022-05-02 22:28:25 +08:00
|
|
|
bool ignore_y = false;
|
2022-08-13 18:26:13 +08:00
|
|
|
real_t neighbor_distance = 0.0;
|
2022-05-02 22:28:25 +08:00
|
|
|
int max_neighbors = 0;
|
|
|
|
real_t time_horizon = 0.0;
|
|
|
|
real_t max_speed = 0.0;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
2020-05-12 23:01:17 +08:00
|
|
|
real_t path_max_distance = 3.0;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
Vector3 target_location;
|
2022-12-07 05:30:34 +08:00
|
|
|
bool target_position_submitted = false;
|
2022-09-20 13:56:54 +08:00
|
|
|
Ref<NavigationPathQueryParameters3D> navigation_query;
|
|
|
|
Ref<NavigationPathQueryResult3D> navigation_result;
|
2022-12-12 01:02:35 +08:00
|
|
|
int navigation_path_index = 0;
|
2020-05-12 23:01:17 +08:00
|
|
|
bool velocity_submitted = false;
|
2020-01-10 19:22:34 +08:00
|
|
|
Vector3 prev_safe_velocity;
|
|
|
|
/// The submitted target velocity
|
|
|
|
Vector3 target_velocity;
|
2020-05-12 23:01:17 +08:00
|
|
|
bool target_reached = false;
|
|
|
|
bool navigation_finished = true;
|
2020-01-10 19:22:34 +08:00
|
|
|
// No initialized on purpose
|
2022-05-02 22:28:25 +08:00
|
|
|
uint32_t update_frame_id = 0;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
|
|
|
public:
|
2020-03-27 05:49:16 +08:00
|
|
|
NavigationAgent3D();
|
|
|
|
virtual ~NavigationAgent3D();
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
RID get_rid() const {
|
|
|
|
return agent;
|
|
|
|
}
|
|
|
|
|
2022-05-21 04:55:27 +08:00
|
|
|
void set_avoidance_enabled(bool p_enabled);
|
|
|
|
bool get_avoidance_enabled() const;
|
|
|
|
|
2022-06-01 12:45:12 +08:00
|
|
|
void set_agent_parent(Node *p_agent_parent);
|
|
|
|
|
2022-06-15 05:34:43 +08:00
|
|
|
void set_navigation_layers(uint32_t p_navigation_layers);
|
|
|
|
uint32_t get_navigation_layers() const;
|
2022-03-20 04:47:02 +08:00
|
|
|
|
2022-06-19 19:23:13 +08:00
|
|
|
void set_navigation_layer_value(int p_layer_number, bool p_value);
|
|
|
|
bool get_navigation_layer_value(int p_layer_number) const;
|
|
|
|
|
2022-10-06 07:24:45 +08:00
|
|
|
void set_path_metadata_flags(BitField<NavigationPathQueryParameters3D::PathMetadataFlags> p_flags);
|
|
|
|
BitField<NavigationPathQueryParameters3D::PathMetadataFlags> get_path_metadata_flags() const {
|
|
|
|
return path_metadata_flags;
|
|
|
|
}
|
|
|
|
|
2022-06-15 02:39:15 +08:00
|
|
|
void set_navigation_map(RID p_navigation_map);
|
|
|
|
RID get_navigation_map() const;
|
|
|
|
|
2022-06-19 01:11:49 +08:00
|
|
|
void set_path_desired_distance(real_t p_dd);
|
|
|
|
real_t get_path_desired_distance() const {
|
|
|
|
return path_desired_distance;
|
|
|
|
}
|
|
|
|
|
2020-01-10 19:22:34 +08:00
|
|
|
void set_target_desired_distance(real_t p_dd);
|
|
|
|
real_t get_target_desired_distance() const {
|
|
|
|
return target_desired_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_radius(real_t p_radius);
|
|
|
|
real_t get_radius() const {
|
|
|
|
return radius;
|
|
|
|
}
|
|
|
|
|
2020-02-10 22:24:00 +08:00
|
|
|
void set_agent_height_offset(real_t p_hh);
|
|
|
|
real_t get_agent_height_offset() const {
|
2020-01-10 19:22:34 +08:00
|
|
|
return navigation_height_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_ignore_y(bool p_ignore_y);
|
|
|
|
bool get_ignore_y() const {
|
|
|
|
return ignore_y;
|
|
|
|
}
|
|
|
|
|
2022-08-13 18:26:13 +08:00
|
|
|
void set_neighbor_distance(real_t p_distance);
|
|
|
|
real_t get_neighbor_distance() const {
|
|
|
|
return neighbor_distance;
|
2020-01-10 19:22:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_max_neighbors(int p_count);
|
|
|
|
int get_max_neighbors() const {
|
|
|
|
return max_neighbors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_time_horizon(real_t p_time);
|
|
|
|
real_t get_time_horizon() const {
|
|
|
|
return time_horizon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_max_speed(real_t p_max_speed);
|
|
|
|
real_t get_max_speed() const {
|
|
|
|
return max_speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_path_max_distance(real_t p_pmd);
|
|
|
|
real_t get_path_max_distance();
|
|
|
|
|
|
|
|
void set_target_location(Vector3 p_location);
|
|
|
|
Vector3 get_target_location() const;
|
|
|
|
|
|
|
|
Vector3 get_next_location();
|
|
|
|
|
2022-10-06 07:24:45 +08:00
|
|
|
Ref<NavigationPathQueryResult3D> get_current_navigation_result() const {
|
|
|
|
return navigation_result;
|
|
|
|
}
|
|
|
|
const Vector<Vector3> &get_current_navigation_path() const {
|
|
|
|
return navigation_result->get_path();
|
|
|
|
}
|
2022-12-12 01:02:35 +08:00
|
|
|
int get_current_navigation_path_index() const {
|
|
|
|
return navigation_path_index;
|
2020-01-10 19:22:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
real_t distance_to_target() const;
|
|
|
|
bool is_target_reached() const;
|
|
|
|
bool is_target_reachable();
|
|
|
|
bool is_navigation_finished();
|
|
|
|
Vector3 get_final_location();
|
|
|
|
|
|
|
|
void set_velocity(Vector3 p_velocity);
|
|
|
|
void _avoidance_done(Vector3 p_new_velocity);
|
|
|
|
|
2022-09-19 23:43:15 +08:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2020-01-10 19:22:34 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void update_navigation();
|
2022-03-20 04:47:02 +08:00
|
|
|
void _request_repath();
|
2021-04-27 18:31:50 +08:00
|
|
|
void _check_distance_to_target();
|
2020-01-10 19:22:34 +08:00
|
|
|
};
|
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#endif // NAVIGATION_AGENT_3D_H
|