From 0de3390cf1766f1980cf3d2494576ab63756ab7c Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 5 Aug 2024 13:58:52 +0200 Subject: [PATCH] fix: unit movement is now operated by Unit class --- src/rts_states.cpp | 12 ++++-------- src/rts_states.hpp | 1 - src/unit.cpp | 4 ++++ src/unit.hpp | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rts_states.cpp b/src/rts_states.cpp index 011037d..a83f965 100644 --- a/src/rts_states.cpp +++ b/src/rts_states.cpp @@ -22,6 +22,8 @@ void MoveTo::_ready() { void MoveTo::_end_state() { this->agent->disconnect("velocity_computed", this->nav_velocity_computed); this->agent->set_target_position(this->parent_unit->get_global_position()); + this->agent->set_velocity({0.f, 0.f, 0.f}); + this->parent_unit->set_velocity({0.f, 0.f, 0.f}); } void MoveTo::_process(double delta_time) { @@ -36,10 +38,6 @@ void MoveTo::_process(double delta_time) { this->calculate_path(); } -void MoveTo::_physics_process(double delta) { - this->parent_unit->move_and_slide(); -} - void MoveTo::calculate_path() { gd::Vector3 const target_pos{this->target_node->get_global_position()}; this->agent->set_target_position(target_pos); @@ -56,13 +54,11 @@ void MoveTo::on_velocity_computed(gd::Vector3 vel) { } float MoveTo::target_delta_position() const { - return this->target_position_at_last - .distance_to(this->target_node->get_global_position()); + return this->target_position_at_last.distance_to(this->target_node->get_global_position()); } float MoveTo::distance_to_target() const { - return this->target_position_at_last - .distance_to(this->parent_unit->get_global_position()); + return this->target_position_at_last.distance_to(this->parent_unit->get_global_position()); } double MoveTo::get_repath_interval() const { diff --git a/src/rts_states.hpp b/src/rts_states.hpp index ce032ac..7504760 100644 --- a/src/rts_states.hpp +++ b/src/rts_states.hpp @@ -15,7 +15,6 @@ public: virtual void _ready() override; virtual void _end_state() override; virtual void _process(double delta_time) override; - virtual void _physics_process(double delta_time) override; void calculate_path(); void on_velocity_computed(gd::Vector3 vel); float target_delta_position() const; diff --git a/src/unit.cpp b/src/unit.cpp index cdc7dbe..33574c8 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -28,6 +28,10 @@ void Unit::_enter_tree() { GDGAMEONLY(); this->health->connect("death", callable_mp(this, &Unit::on_death)); } +void Unit::_physics_process(double delta_time) { + this->move_and_slide(); +} + void Unit::stop_plan() { this->current_goal.unref(); this->current_plan.clear(); diff --git a/src/unit.hpp b/src/unit.hpp index 6ebf318..32cdff3 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -26,6 +26,7 @@ class Unit : public gd::CharacterBody3D { static void _bind_methods(); public: virtual void _enter_tree() override; + virtual void _physics_process(double delta_time) override; void stop_plan(); void begin_marker_temporary(GoalMarker *marker);