feat: units hold formation while patrolling

This commit is contained in:
Sara 2025-07-21 16:50:58 +02:00
parent c05d3aa28f
commit ec6fc76335
7 changed files with 31 additions and 11 deletions

View file

@ -46,6 +46,10 @@ NavigationAgent3D *WretchedState::get_nav() const {
return this->nav;
}
void WretchedPatrolState::set_patrol_target(Vector3 path_point) {
get_nav()->set_target_position(path_point + get_target()->get_unit_offset_3d());
}
void WretchedPatrolState::enter_state() {
this->path = get_target()->get_unit()->get_patrol_path();
@ -53,13 +57,13 @@ void WretchedPatrolState::enter_state() {
get_target()->set_movement_speed(max_speed);
get_nav()->set_max_speed(max_speed);
Vector3 const nav_target{ this->path->get_closest_point(get_target()->get_global_position(), &this->path_point) };
get_nav()->set_target_position(nav_target);
set_patrol_target(nav_target);
}
void WretchedPatrolState::process(double delta) {
if (get_nav()->is_navigation_finished()) {
this->path_point += 1;
get_nav()->set_target_position(this->path->point_at(this->path_point));
set_patrol_target(this->path->point_at(this->path_point));
}
Vector3 const direction{ get_target()->get_global_position().direction_to(get_nav()->get_next_path_position()) };
get_target()->set_movement_direction(Vector2{ direction.x, direction.z }.normalized());