Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
Pathfinding Class Reference

Component responsible for AI pathfinding using a navigation graph. More...

#include <pathfinding.h>

Inheritance diagram for Pathfinding:
[legend]

Public Member Functions

 Pathfinding ()
 
void update (float dt) override
 Update is left empty as the pathfinding component does not require per-frame updates.
 
Pathfindinggenerate_path_to_position (Vector3 origin, Vector3 target)
 Generates a path to the specified target GameObject.
 
Pathfindinggenerate_path_to_position ()
 
Pathfindinggenerate_path_to_target (Vector3 origin)
 Generates a path to the target GameObject using the A* algorithm.
 
Pathfindinggenerate_path_to_target ()
 
Pathfindinggenerate_path_to_target_game_object ()
 Generates a path to the current target GameObject using the A* algorithm.
 
std::vector< std::reference_wrapper< GameObject > > & get_path ()
 Retrieves the current path of the AI agent.
 
std::optional< GraphPositionfind_closest_node (const Vector3 &world_position) const
 Finds the closest navigation node to the specified world position.
 
std::optional< Vector3get_origin () const
 Getters and Setters for origin (positions)
 
Pathfindingset_origin (Vector3 origin)
 
std::optional< Vector3get_target () const
 Getters and Setters for target (positions)
 
Pathfindingset_target (Vector3 target)
 
std::optional< std::reference_wrapper< GameObject > > get_target_game_object () const
 Getters and Setters for target (GameObject)
 
Pathfindingset_target_game_object (GameObject &target)
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
- Public Member Functions inherited from Component
 Component ()
 
virtual ~Component ()=default
 
bool active () const noexcept
 Checks if the component is active.
 
Componentactive (bool value) noexcept
 
bool marked_for_deletion () const noexcept
 Activates the component.
 
Componentmark_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.
 
Componentparent (GameObject &parent)
 
Componentparent (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)
 

Detailed Description

Component responsible for AI pathfinding using a navigation graph.

This component generates paths for AI-controlled GameObjects to navigate through the environment based on a NavigationGraph.

NOTE: This component requires a NavigationGraph component to be present on the same GameObject to function correctly.

Usage:

Constructor & Destructor Documentation

◆ Pathfinding()

Pathfinding::Pathfinding ( )

Member Function Documentation

◆ find_closest_node()

std::optional< GraphPosition > Pathfinding::find_closest_node ( const Vector3 world_position) const

Finds the closest navigation node to the specified world position.

Parameters
world_positionThe world position to find the closest navigation node to.
Returns
An optional GraphPosition of the closest navigation node if found, std::nullopt otherwise.

◆ generate_path_to_position() [1/2]

Pathfinding & Pathfinding::generate_path_to_position ( )

◆ generate_path_to_position() [2/2]

Pathfinding & Pathfinding::generate_path_to_position ( Vector3  origin,
Vector3  target 
)

Generates a path to the specified target GameObject.

Note
This can only be called if the parent GameObject has a NavigationGraph component.
Parameters
targetThe target GameObject to generate a path to.
Returns
Reference to the Pathfinding instance for method chaining.

◆ generate_path_to_target() [1/2]

Pathfinding & Pathfinding::generate_path_to_target ( )

◆ generate_path_to_target() [2/2]

Pathfinding & Pathfinding::generate_path_to_target ( Vector3  origin)

Generates a path to the target GameObject using the A* algorithm.

Note
This can only be called if the parent GameObject has a NavigationGraph component.
Returns
Reference to the Pathfinding instance for method chaining.

◆ generate_path_to_target_game_object()

Pathfinding & Pathfinding::generate_path_to_target_game_object ( )

Generates a path to the current target GameObject using the A* algorithm.

Note
This can only be called if the parent GameObject has a NavigationGraph component and a target GameObject has been set.
Returns
Reference to the Pathfinding instance for method chaining.

◆ get_origin()

std::optional< Vector3 > Pathfinding::get_origin ( ) const

Getters and Setters for origin (positions)

◆ get_path()

std::vector< std::reference_wrapper< GameObject > > & Pathfinding::get_path ( )

Retrieves the current path of the AI agent.

Returns
A constant reference to the vector of GameObject references representing the path. These game objects are children of tiles in the NavigationGraph and have NavigationNode components.

◆ get_target()

std::optional< Vector3 > Pathfinding::get_target ( ) const

Getters and Setters for target (positions)

◆ get_target_game_object()

std::optional< std::reference_wrapper< GameObject > > Pathfinding::get_target_game_object ( ) const

Getters and Setters for target (GameObject)

◆ set_origin()

Pathfinding & Pathfinding::set_origin ( Vector3  origin)

◆ set_target()

Pathfinding & Pathfinding::set_target ( Vector3  target)

◆ set_target_game_object()

Pathfinding & Pathfinding::set_target_game_object ( GameObject target)

◆ type_name()

std::string Pathfinding::type_name ( ) const
overridevirtual

Provides a consistent type name for the component.

Returns
A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.

Implements Component.

◆ update()

void Pathfinding::update ( float  dt)
inlineoverridevirtual

Update is left empty as the pathfinding component does not require per-frame updates.

Implements Component.


The documentation for this class was generated from the following file: