|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
Component responsible for controlling AI behavior. More...
#include <ai_controller.h>
Public Member Functions | |
| AIController (GameObject &pathfinding_game_object) | |
| void | update (float dt) override |
| void | chase (float dt) |
| Handles chasing behavior towards the chase target. | |
| void | patrol (float dt) |
| Handles patrolling behavior between patrol points. | |
| void | try_traverse_graph (Transform &source, Transform &target, float dt) |
| Attempts to traverse the navigation graph from source to target. | |
| AIControllerMode | get_mode () const |
| AIController & | set_mode (AIControllerMode mode) |
| std::optional< std::reference_wrapper< GameObject > > | get_chase_target () const |
| AIController & | set_chase_target (GameObject &target) |
| AIController & | clear_chase_target () |
| std::optional< std::reference_wrapper< GameObject > > | get_patrol_target () const |
| AIController & | set_patrol_target (GameObject &target) |
| AIController & | clear_patrol_target () |
| float | get_arrival_threshold () const |
| AIController & | set_arrival_threshold (float threshold) |
| float | get_speed () const |
| AIController & | set_speed (float speed) |
| float | get_width () const |
| AIController & | set_width (float width) |
| float | get_height () const |
| AIController & | set_height (float height) |
| std::vector< std::reference_wrapper< GameObject > > & | get_path () |
| bool | enable_graph_traversal () noexcept |
| bool | disable_graph_traversal () noexcept |
| size_t | add_on_patrol_complete_action (std::function< void(AIController &)> action) |
| void | remove_on_patrol_complete_action (size_t index) |
| std::string | type_name () const override |
| Provides a consistent type name for the component. | |
Public Member Functions inherited from Renderable | |
| Renderable () | |
| Renderable (int layer) | |
| ~Renderable () override=default | |
| Renderable & | order_in_layer (int layer) |
| int | order_in_layer () const |
| void | set_render_strategy (Component &component) |
| virtual IRenderingStrategy & | render_strategy () const |
| std::string | type_name () const override |
| Provides a consistent type name for the component. | |
| Renderable & | disable_draw () noexcept |
| Renderable & | enable_draw () noexcept |
| bool | should_draw () const noexcept |
Public Member Functions inherited from Component | |
| Component () | |
| virtual | ~Component ()=default |
| bool | active () const noexcept |
| Checks if the component is active. | |
| Component & | active (bool value) noexcept |
| bool | marked_for_deletion () const noexcept |
| Activates the component. | |
| Component & | mark_for_deletion () noexcept |
| virtual void | on_attach () |
| Called when the component is attached to a GameObject. | |
| virtual void | on_detach () |
| Called when the component is detached from a GameObject. | |
| virtual void | on_serialize (std::vector< uint8_t > &) const |
| Serializes the component's state into a byte array. | |
| virtual void | on_deserialize (const std::vector< uint8_t > &, size_t &) |
| Deserializes the component's state from a byte array. | |
| const std::optional< std::reference_wrapper< GameObject > > & | parent () const noexcept |
| Gets the parent GameObject of this component. | |
| std::optional< std::reference_wrapper< GameObject > > & | parent () noexcept |
| Gets the parent GameObject of this component. | |
| Component & | parent (GameObject &parent) |
| Component & | parent (std::nullopt_t nullopt) |
| size_t | add_on_attach (const std::function< void(Component &)> &action) |
| Retrieves the type information of the component. | |
| void | remove_on_attach (size_t index) |
| size_t | add_on_detach (const std::function< void(Component &)> &action) |
| Adds an action to be performed when the component is attached. | |
| void | remove_on_detach (size_t index) |
Additional Inherited Members | |
Protected Attributes inherited from Renderable | |
| std::unique_ptr< IRenderingStrategy > | render_strategy_ |
| int | ordering_layer_ = 0 |
| bool | draw {true} |
Component responsible for controlling AI behavior.
This component utilizes the Pathfinding component to navigate the AI-controlled GameObject towards a specified target GameObject.
The AIController can operate in different modes, such as PATROL and CHASE, allowing for versatile AI behaviors.
There still is a possibility that the AI gets stuck on corners or obstacles depending on the navigation graph and collider setup. It has some basic stuck detection and will try to recalculate the path if it detects that it's not moving.
NOTE: for this to work you need to set up a proper navigation graph using the Pathfinding component and ensure that the AI GameObject has appropriate colliders (and Rigidbody2D if using physics-based movement).
Usage:
| AIController::AIController | ( | GameObject & | pathfinding_game_object | ) |
| size_t AIController::add_on_patrol_complete_action | ( | std::function< void(AIController &)> | action | ) |
| void AIController::chase | ( | float | dt | ) |
Handles chasing behavior towards the chase target.
| AIController & AIController::clear_chase_target | ( | ) |
| AIController & AIController::clear_patrol_target | ( | ) |
|
noexcept |
|
noexcept |
| float AIController::get_arrival_threshold | ( | ) | const |
| std::optional< std::reference_wrapper< GameObject > > AIController::get_chase_target | ( | ) | const |
| float AIController::get_height | ( | ) | const |
| AIControllerMode AIController::get_mode | ( | ) | const |
| std::vector< std::reference_wrapper< GameObject > > & AIController::get_path | ( | ) |
| std::optional< std::reference_wrapper< GameObject > > AIController::get_patrol_target | ( | ) | const |
| float AIController::get_speed | ( | ) | const |
| float AIController::get_width | ( | ) | const |
| void AIController::patrol | ( | float | dt | ) |
Handles patrolling behavior between patrol points.
| void AIController::remove_on_patrol_complete_action | ( | size_t | index | ) |
| AIController & AIController::set_arrival_threshold | ( | float | threshold | ) |
| AIController & AIController::set_chase_target | ( | GameObject & | target | ) |
| AIController & AIController::set_height | ( | float | height | ) |
| AIController & AIController::set_mode | ( | AIControllerMode | mode | ) |
| AIController & AIController::set_patrol_target | ( | GameObject & | target | ) |
| AIController & AIController::set_speed | ( | float | speed | ) |
| AIController & AIController::set_width | ( | float | width | ) |
Attempts to traverse the navigation graph from source to target.
| source | The Transform of the AI-controlled GameObject. |
| target | The Transform of the target GameObject. |
| dt | The delta time since the last update. |
|
overridevirtual |
Provides a consistent type name for the component.
Implements Component.
|
overridevirtual |
Implements Component.