Path: blob/master/modules/navigation_3d/nav_agent_3d.h
10277 views
/**************************************************************************/1/* nav_agent_3d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "nav_rid_3d.h"3334#include "core/object/class_db.h"35#include "core/templates/self_list.h"36#include "servers/navigation/navigation_globals.h"3738#include <Agent2d.h>39#include <Agent3d.h>4041class NavMap3D;4243class NavAgent3D : public NavRid3D {44Vector3 position;45Vector3 target_position;46Vector3 velocity;47Vector3 velocity_forced;48real_t height = NavigationDefaults3D::AVOIDANCE_AGENT_HEIGHT;49real_t radius = NavigationDefaults3D::AVOIDANCE_AGENT_RADIUS;50real_t max_speed = NavigationDefaults3D::AVOIDANCE_AGENT_MAX_SPEED;51real_t time_horizon_agents = NavigationDefaults3D::AVOIDANCE_AGENT_TIME_HORIZON_AGENTS;52real_t time_horizon_obstacles = NavigationDefaults3D::AVOIDANCE_AGENT_TIME_HORIZON_OBSTACLES;53int max_neighbors = NavigationDefaults3D::AVOIDANCE_AGENT_MAX_NEIGHBORS;54real_t neighbor_distance = NavigationDefaults3D::AVOIDANCE_AGENT_NEIGHBOR_DISTANCE;55Vector3 safe_velocity;56bool clamp_speed = true; // Experimental, clamps velocity to max_speed.5758NavMap3D *map = nullptr;5960RVO2D::Agent2D rvo_agent_2d;61RVO3D::Agent3D rvo_agent_3d;62bool use_3d_avoidance = false;63bool avoidance_enabled = false;6465uint32_t avoidance_layers = 1;66uint32_t avoidance_mask = 1;67real_t avoidance_priority = 1.0;6869Callable avoidance_callback;7071bool agent_dirty = true;7273uint32_t last_map_iteration_id = 0;74bool paused = false;7576SelfList<NavAgent3D> sync_dirty_request_list_element;7778public:79NavAgent3D();80~NavAgent3D();8182void set_avoidance_enabled(bool p_enabled);83bool is_avoidance_enabled() { return avoidance_enabled; }8485void set_use_3d_avoidance(bool p_enabled);86bool get_use_3d_avoidance() { return use_3d_avoidance; }8788void set_map(NavMap3D *p_map);89NavMap3D *get_map() { return map; }9091bool is_map_changed();9293RVO2D::Agent2D *get_rvo_agent_2d() { return &rvo_agent_2d; }94RVO3D::Agent3D *get_rvo_agent_3d() { return &rvo_agent_3d; }9596void set_avoidance_callback(Callable p_callback);97bool has_avoidance_callback() const;9899void dispatch_avoidance_callback();100101void set_neighbor_distance(real_t p_neighbor_distance);102real_t get_neighbor_distance() const { return neighbor_distance; }103104void set_max_neighbors(int p_max_neighbors);105int get_max_neighbors() const { return max_neighbors; }106107void set_time_horizon_agents(real_t p_time_horizon);108real_t get_time_horizon_agents() const { return time_horizon_agents; }109110void set_time_horizon_obstacles(real_t p_time_horizon);111real_t get_time_horizon_obstacles() const { return time_horizon_obstacles; }112113void set_radius(real_t p_radius);114real_t get_radius() const { return radius; }115116void set_height(real_t p_height);117real_t get_height() const { return height; }118119void set_max_speed(real_t p_max_speed);120real_t get_max_speed() const { return max_speed; }121122void set_position(const Vector3 p_position);123const Vector3 &get_position() const { return position; }124125void set_target_position(const Vector3 p_target_position);126const Vector3 &get_target_position() const { return target_position; }127128void set_velocity(const Vector3 p_velocity);129const Vector3 &get_velocity() const { return velocity; }130131void set_velocity_forced(const Vector3 p_velocity);132const Vector3 &get_velocity_forced() const { return velocity_forced; }133134void set_avoidance_layers(uint32_t p_layers);135uint32_t get_avoidance_layers() const { return avoidance_layers; }136137void set_avoidance_mask(uint32_t p_mask);138uint32_t get_avoidance_mask() const { return avoidance_mask; }139140void set_avoidance_priority(real_t p_priority);141real_t get_avoidance_priority() const { return avoidance_priority; }142143void set_paused(bool p_paused);144bool get_paused() const;145146bool is_dirty() const;147void sync();148void request_sync();149void cancel_sync_request();150151// Updates this agent with rvo data after the rvo simulation avoidance step.152void update();153154// RVO debug data from the last frame update.155const Dictionary get_avoidance_data() const;156157private:158void _update_rvo_agent_properties();159};160161162