From f9400723122f13bae7c7549235419154508e8dc2 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 19 Jun 2024 10:58:50 +0200 Subject: [PATCH] feat: implemented basic "can_see_target" --- src/unit_world_state.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unit_world_state.cpp b/src/unit_world_state.cpp index 785b515..62e42a1 100644 --- a/src/unit_world_state.cpp +++ b/src/unit_world_state.cpp @@ -1,6 +1,10 @@ #include "unit_world_state.hpp" #include "unit.hpp" #include "utils/godot_macros.hpp" +#include +#include +#include +#include #include void UnitWorldState::_bind_methods() { @@ -20,7 +24,10 @@ void UnitWorldState::_enter_tree() { GDGAMEONLY(); } bool UnitWorldState::get_can_see_target() const { - return false; + gd::Transform3D const eyes = this->parent_unit->get_eye_transform(); + gd::Transform3D const target = this->target_node->get_global_transform(); + gd::Ref const query{gd::PhysicsRayQueryParameters3D::create(eyes.origin, target.origin, 0x1 | 0x4, {this->target_node})}; + return this->parent_unit->get_world_3d()->get_direct_space_state()->intersect_ray(query).is_empty(); } bool UnitWorldState::get_is_at_target() const {