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:
Morph01
2024-08-16 14:56:57 +02:00
parent 1662691b6e
commit 6160561498
18 changed files with 2902 additions and 13 deletions

60
src/Zombie.cpp Normal file
View 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

33
src/Zombie.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/navigation_agent3d.hpp>
#include <godot_cpp/variant/node_path.hpp>
#include "FirstPersonPlayer.h"
namespace blitz {
class Zombie : public godot::CharacterBody3D {
GDCLASS(Zombie, godot::CharacterBody3D)
protected:
static void _bind_methods();
public:
Zombie();
~Zombie();
void _ready();
void _process(float delta);
private:
godot::NavigationAgent3D* m_NavigationAgent;
FirstPersonPlayer* m_Player;
godot::NodePath m_PlayerPath;
godot::Vector3 m_Velocity;
void set_m_PlayerPath(const godot::NodePath& path);
godot::NodePath get_m_PlayerPath() const;
};
} // namespace blitz

View File

@@ -4,6 +4,7 @@
#include "FirstPersonPlayer.h"
#include "Player.h"
#include "SpringArmPivot.h"
#include "Zombie.h"
#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
@@ -20,6 +21,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<blitz::SpringArmPivot>();
ClassDB::register_class<blitz::FirstPersonPlayer>();
ClassDB::register_class<blitz::Bullet>();
ClassDB::register_class<blitz::Zombie>();
}
void uninitialize_example_module(ModuleInitializationLevel p_level) {