Random spawn of zombies

This commit is contained in:
Morph01
2024-08-22 19:40:32 +02:00
parent faf6a9116d
commit 5c6f82c5d7
5 changed files with 137 additions and 53 deletions

View File

@@ -1,6 +1,8 @@
#include "Zombie.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/core/math.hpp>
using namespace godot;
@@ -32,8 +34,13 @@ void Zombie::_ready() {
}
#endif
m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->find_child("FirstPersonPlayer"));
DEV_ASSERT(m_Player);
godot::Node* scene_root = Object::cast_to<godot::Node>(get_tree()->get_root()->get_child(0));
if (scene_root) {
m_Player = Object::cast_to<FirstPersonPlayer>(scene_root->find_child("FirstPersonPlayer", true));
DEV_ASSERT(m_Player);
} else {
ERR_PRINT("Scene root not found or invalid.");
}
m_NavigationAgent = Object::cast_to<NavigationAgent3D>(find_child("NavigationAgent3D"));
DEV_ASSERT(m_NavigationAgent);
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree"));