fix: cluefinder now uses scores instead of first found

This commit is contained in:
Sara Gerretsen 2025-11-04 21:19:05 +01:00
parent 534b527f61
commit b1667c68a1
3 changed files with 14 additions and 6 deletions

View file

@ -1,5 +1,6 @@
#include "clue_finder.h"
#include "core/config/engine.h"
#include "core/math/math_defs.h"
#include "scene/3d/xr/xr_nodes.h"
#include "scene/main/node.h"
@ -59,12 +60,15 @@ ClueFinder *ClueFinder::get_singleton() {
}
ClueMarker *ClueFinder::find_current_clue() {
float best_score{ Math::INF };
ClueMarker *best_marker{ nullptr };
for (ClueMarker *marker : this->clue_markers) {
if (marker->is_visible()) {
return marker;
if (marker->score_in_view() < best_score) {
print_line("found marker ", marker->get_path());
best_marker = marker;
}
}
return nullptr;
return best_marker;
}
void ClueFinder::register_clue_marker(ClueMarker *marker) {

View file

@ -31,7 +31,7 @@ void ClueMarker::_notification(int what) {
}
}
bool ClueMarker::is_visible() const {
float ClueMarker::score_in_view() const {
Transform3D const viewpoint{ ClueFinder::get_singleton()->get_global_transform() };
Basis const basis{ viewpoint.get_basis() };
Vector3 const pos_relative{ get_global_position() - viewpoint.get_origin() };
@ -40,7 +40,11 @@ bool ClueMarker::is_visible() const {
return false;
}
Vector3 const transformed_dir{ pos_transformed.normalized() };
return Math::abs(transformed_dir.x) < 0.5 || Math::abs(transformed_dir.y) < 0.5;
float max{ pos_transformed.z / 5.f };
if (Math::abs(transformed_dir.x) < max && Math::abs(transformed_dir.y) < max) {
return Math::INF;
}
return pos_transformed.z * (Math::abs(transformed_dir.x) + Math::abs(transformed_dir.y));
}
void ClueMarker::reveal() {

View file

@ -14,7 +14,7 @@ protected:
void _notification(int what);
public:
bool is_visible() const;
float score_in_view() const;
void reveal();
void set_clue_id(NetworkData::ClueID id);
NetworkData::ClueID get_clue_id() const;