fix: unit movement is now operated by Unit class

This commit is contained in:
Sara 2024-08-05 13:58:52 +02:00
parent 6a20073452
commit 0de3390cf1
4 changed files with 9 additions and 9 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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();

View file

@ -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);