fix: unit movement is now operated by Unit class
This commit is contained in:
parent
6a20073452
commit
0de3390cf1
|
@ -22,6 +22,8 @@ void MoveTo::_ready() {
|
||||||
void MoveTo::_end_state() {
|
void MoveTo::_end_state() {
|
||||||
this->agent->disconnect("velocity_computed", this->nav_velocity_computed);
|
this->agent->disconnect("velocity_computed", this->nav_velocity_computed);
|
||||||
this->agent->set_target_position(this->parent_unit->get_global_position());
|
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) {
|
void MoveTo::_process(double delta_time) {
|
||||||
|
@ -36,10 +38,6 @@ void MoveTo::_process(double delta_time) {
|
||||||
this->calculate_path();
|
this->calculate_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveTo::_physics_process(double delta) {
|
|
||||||
this->parent_unit->move_and_slide();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MoveTo::calculate_path() {
|
void MoveTo::calculate_path() {
|
||||||
gd::Vector3 const target_pos{this->target_node->get_global_position()};
|
gd::Vector3 const target_pos{this->target_node->get_global_position()};
|
||||||
this->agent->set_target_position(target_pos);
|
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 {
|
float MoveTo::target_delta_position() const {
|
||||||
return this->target_position_at_last
|
return this->target_position_at_last.distance_to(this->target_node->get_global_position());
|
||||||
.distance_to(this->target_node->get_global_position());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float MoveTo::distance_to_target() const {
|
float MoveTo::distance_to_target() const {
|
||||||
return this->target_position_at_last
|
return this->target_position_at_last.distance_to(this->parent_unit->get_global_position());
|
||||||
.distance_to(this->parent_unit->get_global_position());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double MoveTo::get_repath_interval() const {
|
double MoveTo::get_repath_interval() const {
|
||||||
|
|
|
@ -15,7 +15,6 @@ public:
|
||||||
virtual void _ready() override;
|
virtual void _ready() override;
|
||||||
virtual void _end_state() override;
|
virtual void _end_state() override;
|
||||||
virtual void _process(double delta_time) override;
|
virtual void _process(double delta_time) override;
|
||||||
virtual void _physics_process(double delta_time) override;
|
|
||||||
void calculate_path();
|
void calculate_path();
|
||||||
void on_velocity_computed(gd::Vector3 vel);
|
void on_velocity_computed(gd::Vector3 vel);
|
||||||
float target_delta_position() const;
|
float target_delta_position() const;
|
||||||
|
|
|
@ -28,6 +28,10 @@ void Unit::_enter_tree() { GDGAMEONLY();
|
||||||
this->health->connect("death", callable_mp(this, &Unit::on_death));
|
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() {
|
void Unit::stop_plan() {
|
||||||
this->current_goal.unref();
|
this->current_goal.unref();
|
||||||
this->current_plan.clear();
|
this->current_plan.clear();
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Unit : public gd::CharacterBody3D {
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
virtual void _enter_tree() override;
|
virtual void _enter_tree() override;
|
||||||
|
virtual void _physics_process(double delta_time) override;
|
||||||
|
|
||||||
void stop_plan();
|
void stop_plan();
|
||||||
void begin_marker_temporary(GoalMarker *marker);
|
void begin_marker_temporary(GoalMarker *marker);
|
||||||
|
|
Loading…
Reference in a new issue