Path: blob/master/modules/navigation_2d/nav_agent_2d.h
10277 views
/**************************************************************************/1/* nav_agent_2d.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_2d.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>3940class NavMap2D;4142class NavAgent2D : public NavRid2D {43Vector2 position;44Vector2 target_position;45Vector2 velocity;46Vector2 velocity_forced;47real_t radius = NavigationDefaults2D::AVOIDANCE_AGENT_RADIUS;48real_t max_speed = NavigationDefaults2D::AVOIDANCE_AGENT_MAX_SPEED;49real_t time_horizon_agents = NavigationDefaults2D::AVOIDANCE_AGENT_TIME_HORIZON_AGENTS;50real_t time_horizon_obstacles = NavigationDefaults2D::AVOIDANCE_AGENT_TIME_HORIZON_OBSTACLES;51int max_neighbors = NavigationDefaults2D::AVOIDANCE_AGENT_MAX_NEIGHBORS;52real_t neighbor_distance = NavigationDefaults2D::AVOIDANCE_AGENT_NEIGHBOR_DISTANCE;53Vector2 safe_velocity;54bool clamp_speed = true; // Experimental, clamps velocity to max_speed.5556NavMap2D *map = nullptr;5758RVO2D::Agent2D rvo_agent;59bool avoidance_enabled = false;6061uint32_t avoidance_layers = 1;62uint32_t avoidance_mask = 1;63real_t avoidance_priority = 1.0;6465Callable avoidance_callback;6667bool agent_dirty = true;6869uint32_t last_map_iteration_id = 0;70bool paused = false;7172SelfList<NavAgent2D> sync_dirty_request_list_element;7374public:75NavAgent2D();76~NavAgent2D();7778void set_avoidance_enabled(bool p_enabled);79bool is_avoidance_enabled() { return avoidance_enabled; }8081void set_map(NavMap2D *p_map);82NavMap2D *get_map() { return map; }8384bool is_map_changed();8586RVO2D::Agent2D *get_rvo_agent() { return &rvo_agent; }8788void set_avoidance_callback(Callable p_callback);89bool has_avoidance_callback() const;9091void dispatch_avoidance_callback();9293void set_neighbor_distance(real_t p_neighbor_distance);94real_t get_neighbor_distance() const { return neighbor_distance; }9596void set_max_neighbors(int p_max_neighbors);97int get_max_neighbors() const { return max_neighbors; }9899void set_time_horizon_agents(real_t p_time_horizon);100real_t get_time_horizon_agents() const { return time_horizon_agents; }101102void set_time_horizon_obstacles(real_t p_time_horizon);103real_t get_time_horizon_obstacles() const { return time_horizon_obstacles; }104105void set_radius(real_t p_radius);106real_t get_radius() const { return radius; }107108void set_max_speed(real_t p_max_speed);109real_t get_max_speed() const { return max_speed; }110111void set_position(const Vector2 &p_position);112Vector2 get_position() const { return position; }113114void set_target_position(const Vector2 &p_target_position);115Vector2 get_target_position() const { return target_position; }116117void set_velocity(const Vector2 &p_velocity);118Vector2 get_velocity() const { return velocity; }119120void set_velocity_forced(const Vector2 &p_velocity);121Vector2 get_velocity_forced() const { return velocity_forced; }122123void set_avoidance_layers(uint32_t p_layers);124uint32_t get_avoidance_layers() const { return avoidance_layers; }125126void set_avoidance_mask(uint32_t p_mask);127uint32_t get_avoidance_mask() const { return avoidance_mask; }128129void set_avoidance_priority(real_t p_priority);130real_t get_avoidance_priority() const { return avoidance_priority; }131132void set_paused(bool p_paused);133bool get_paused() const;134135bool is_dirty() const;136void sync();137void request_sync();138void cancel_sync_request();139140// Updates this agent with rvo data after the rvo simulation avoidance step.141void update();142143// RVO debug data from the last frame update.144const Dictionary get_avoidance_data() const;145146private:147void _update_rvo_agent_properties();148};149150151