generated from Persson-dev/Godot-Xmake
Squashed commit of the following:
commit 4fd60e7874
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date: Fri Aug 16 14:19:29 2024 +0200
bug animation ???
This commit is contained in:
60
src/Zombie.cpp
Normal file
60
src/Zombie.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "Zombie.h"
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
namespace blitz {
|
||||
|
||||
static constexpr float SPEED = 2.0f;
|
||||
|
||||
|
||||
void Zombie::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_m_PlayerPath", "m_PlayerPath"), &Zombie::set_m_PlayerPath);
|
||||
ClassDB::bind_method(D_METHOD("get_m_PlayerPath"), &Zombie::get_m_PlayerPath);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath");
|
||||
}
|
||||
|
||||
Zombie::Zombie() {}
|
||||
|
||||
Zombie::~Zombie() {}
|
||||
|
||||
void Zombie::_ready() {
|
||||
#if DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->find_child("FirstPersonPlayer"));
|
||||
DEV_ASSERT(m_Player);
|
||||
m_NavigationAgent = Object::cast_to<NavigationAgent3D>(find_child("NavigationAgent3D"));
|
||||
DEV_ASSERT(m_NavigationAgent);
|
||||
m_Velocity = Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
void Zombie::_process(float a_Delta) {
|
||||
#if DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
this->set_velocity(m_Velocity);
|
||||
m_NavigationAgent->set_target_position(m_Player->get_global_position());
|
||||
Vector3 next_nav_point = m_NavigationAgent->get_next_path_position();
|
||||
m_Velocity = (next_nav_point - get_global_position()).normalized() * SPEED;
|
||||
this->set_velocity(m_Velocity);
|
||||
look_at(Vector3(m_Player->get_global_position().x, get_global_position().y, m_Player->get_global_position().z), Vector3(0, 1, 0));
|
||||
move_and_slide();
|
||||
}
|
||||
|
||||
void Zombie::set_m_PlayerPath(const NodePath& path) {
|
||||
m_PlayerPath = path;
|
||||
}
|
||||
|
||||
NodePath Zombie::get_m_PlayerPath() const {
|
||||
return m_PlayerPath;
|
||||
}
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user