chore: detector line_of_sight_exists is public

This commit is contained in:
Sara Gerretsen 2026-02-02 20:19:11 +01:00
parent d430da0801
commit dfc5ac680a
2 changed files with 12 additions and 12 deletions

View file

@ -8,17 +8,6 @@ void PlayerDetector::_bind_methods() {
ADD_SIGNAL(MethodInfo(sig_awareness_changed, PropertyInfo(Variant::BOOL, "aware")));
}
// check if there is geometry between detector and player
bool PlayerDetector::line_of_sight_exists() const {
PhysicsDirectSpaceState3D::RayParameters params{ this->ray_params };
params.from = get_global_position();
params.to = PlayerBody::get_singleton()->get_global_position();
PhysicsDirectSpaceState3D *space{ get_world_3d()->get_direct_space_state() };
PhysicsDirectSpaceState3D::RayResult result{};
space->intersect_ray(params, result);
return result.collider == nullptr;
}
// Check if the player is in a bounded area in front of the detector and unobscured.
// As all tests are required to pass, we do them in increasing order of complexity, to minimize unneeded resource use.
bool PlayerDetector::check() const {
@ -82,6 +71,17 @@ void PlayerDetector::_notification(int what) {
}
}
// check if there is geometry between detector and player
bool PlayerDetector::line_of_sight_exists() const {
PhysicsDirectSpaceState3D::RayParameters params{ this->ray_params };
params.from = get_global_position();
params.to = PlayerBody::get_singleton()->get_global_position();
PhysicsDirectSpaceState3D *space{ get_world_3d()->get_direct_space_state() };
PhysicsDirectSpaceState3D::RayResult result{};
space->intersect_ray(params, result);
return result.collider == nullptr;
}
bool PlayerDetector::is_aware_of_player() const {
return this->aware_of_player;
}