fix: projectiles now destroy when hitting non-character objects
This commit is contained in:
parent
9472109d6e
commit
51d07079b2
|
@ -19,11 +19,10 @@ void PelletProjectile::_physics_process(double delta_time) { GDGAMEONLY();
|
||||||
float const speed = this->data->get_projectile_speed()->sample(distance_traveled / this->data->get_range());
|
float const speed = this->data->get_projectile_speed()->sample(distance_traveled / this->data->get_range());
|
||||||
this->distance_traveled += speed;
|
this->distance_traveled += speed;
|
||||||
Vector3 const next_position{this->get_global_position() + this->get_global_transform().basis.get_column(2) * speed};
|
Vector3 const next_position{this->get_global_position() + this->get_global_transform().basis.get_column(2) * speed};
|
||||||
if(this->check_hit(next_position) || this->distance_traveled > this->data->get_range()) {
|
if(this->check_hit(next_position) || this->distance_traveled > this->data->get_range())
|
||||||
this->return_to_pool();
|
this->return_to_pool();
|
||||||
} else {
|
else
|
||||||
this->set_global_position(next_position);
|
this->set_global_position(next_position);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PelletProjectile::check_hit(Vector3 next_position) {
|
bool PelletProjectile::check_hit(Vector3 next_position) {
|
||||||
|
@ -36,7 +35,7 @@ bool PelletProjectile::check_hit(Vector3 next_position) {
|
||||||
return false;
|
return false;
|
||||||
IHealthEntity *health_entity = dynamic_cast<IHealthEntity*>(collider);
|
IHealthEntity *health_entity = dynamic_cast<IHealthEntity*>(collider);
|
||||||
if(health_entity == nullptr)
|
if(health_entity == nullptr)
|
||||||
return false;
|
return true;
|
||||||
health_entity->get_health()->damage(this->data->get_damage());
|
health_entity->get_health()->damage(this->data->get_damage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue