feat: implemented basic "can_see_target"

This commit is contained in:
Sara 2024-06-19 10:58:50 +02:00
parent 8cfbbcce27
commit f940072312

View file

@ -1,6 +1,10 @@
#include "unit_world_state.hpp" #include "unit_world_state.hpp"
#include "unit.hpp" #include "unit.hpp"
#include "utils/godot_macros.hpp" #include "utils/godot_macros.hpp"
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
#include <godot_cpp/classes/world3d.hpp>
#include <godot_cpp/classes/physics_direct_space_state3d.hpp>
#include <godot_cpp/variant/callable_method_pointer.hpp>
#include <godot_cpp/variant/utility_functions.hpp> #include <godot_cpp/variant/utility_functions.hpp>
void UnitWorldState::_bind_methods() { void UnitWorldState::_bind_methods() {
@ -20,7 +24,10 @@ void UnitWorldState::_enter_tree() { GDGAMEONLY();
} }
bool UnitWorldState::get_can_see_target() const { 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<gd::PhysicsRayQueryParameters3D> 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 { bool UnitWorldState::get_is_at_target() const {