chore: detector line_of_sight_exists is public
This commit is contained in:
parent
d430da0801
commit
dfc5ac680a
2 changed files with 12 additions and 12 deletions
|
|
@ -8,17 +8,6 @@ void PlayerDetector::_bind_methods() {
|
||||||
ADD_SIGNAL(MethodInfo(sig_awareness_changed, PropertyInfo(Variant::BOOL, "aware")));
|
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.
|
// 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.
|
// As all tests are required to pass, we do them in increasing order of complexity, to minimize unneeded resource use.
|
||||||
bool PlayerDetector::check() const {
|
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 {
|
bool PlayerDetector::is_aware_of_player() const {
|
||||||
return this->aware_of_player;
|
return this->aware_of_player;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
class PlayerDetector : public Node3D {
|
class PlayerDetector : public Node3D {
|
||||||
GDCLASS(PlayerDetector, Node3D);
|
GDCLASS(PlayerDetector, Node3D);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
bool line_of_sight_exists() const;
|
|
||||||
bool check() const;
|
bool check() const;
|
||||||
void ready();
|
void ready();
|
||||||
void process(double delta);
|
void process(double delta);
|
||||||
|
|
@ -17,6 +16,7 @@ protected:
|
||||||
void _notification(int what);
|
void _notification(int what);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool line_of_sight_exists() const;
|
||||||
bool is_aware_of_player() const;
|
bool is_aware_of_player() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue