diff --git a/include/omath/pathfinding/walk_bot.hpp b/include/omath/pathfinding/walk_bot.hpp new file mode 100644 index 0000000..b7a9fd6 --- /dev/null +++ b/include/omath/pathfinding/walk_bot.hpp @@ -0,0 +1,20 @@ +// +// Created by orange on 4/12/2026. +// +#pragma once +#include "navigation_mesh.hpp" +#include "omath/linear_algebra/vector3.hpp" +#include +namespace omath::pathfinding +{ + class WalkBot + { + public: + void update(const Vector3& bot_position, const Vector3& target_position, float min_node_distance) const; + + private: + std::weak_ptr m_mav_mesh; + float m_min_distance_to_path_point; + std::optional&)>> m_on_next_path_node = nullptr; + }; +} // namespace omath::pathfinding \ No newline at end of file diff --git a/source/pathfinding/walk_bot.cpp b/source/pathfinding/walk_bot.cpp new file mode 100644 index 0000000..9ae649d --- /dev/null +++ b/source/pathfinding/walk_bot.cpp @@ -0,0 +1,31 @@ +// +// Created by orange on 4/12/2026. +// +#include "omath/pathfinding/walk_bot.hpp" +#include "omath/pathfinding/a_star.hpp" + +namespace omath::pathfinding +{ + + void WalkBot::update(const Vector3& bot_position, const Vector3& target_position, + const float min_node_distance) const + { + const auto nav_mesh = m_mav_mesh.lock(); + + if (!nav_mesh) + return; + + const auto path = Astar::find_path(bot_position, target_position, *nav_mesh); + + if (path.empty()) + return; + + if (!m_on_next_path_node.has_value()) + return; + + if (path.size() > 1 && path.front().distance_to(bot_position) <= min_node_distance) + m_on_next_path_node->operator()(path[1]); + else + m_on_next_path_node->operator()(path.front()); + } +} // namespace omath::pathfinding \ No newline at end of file