generated from Persson-dev/Godot-Xmake
stick pens on walls
This commit is contained in:
56
src/client/Bullet.cpp
Normal file
56
src/client/Bullet.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <client/Bullet.h>
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/physics_direct_space_state3d.hpp>
|
||||
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
|
||||
#include <godot_cpp/classes/world3d.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
using namespace godot;
|
||||
|
||||
static constexpr float SPEED = 20.0f;
|
||||
static constexpr float MaxAlive = 10.0f;
|
||||
|
||||
void Bullet::_bind_methods() {}
|
||||
|
||||
Bullet::Bullet() : m_Stuck(false) {}
|
||||
|
||||
void Bullet::_ready() {}
|
||||
|
||||
Bullet::~Bullet() {}
|
||||
|
||||
void Bullet::_process(float a_Delta) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_LifeTime += a_Delta;
|
||||
if (m_LifeTime > MaxAlive) {
|
||||
queue_free();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Stuck)
|
||||
return;
|
||||
|
||||
Vector3 start = get_position();
|
||||
Vector3 finish = start + get_transform().basis.xform(Vector3{0, 0, -SPEED * a_Delta});
|
||||
|
||||
auto query = PhysicsRayQueryParameters3D::create(start, finish, 1);
|
||||
auto result = get_world_3d()->get_direct_space_state()->intersect_ray(query);
|
||||
|
||||
if (result.is_empty()) {
|
||||
set_position(finish);
|
||||
return;
|
||||
}
|
||||
|
||||
m_Stuck = true;
|
||||
Vector3 intersectPoint = result["position"];
|
||||
|
||||
auto* head = get_node<Node3D>("Armature");
|
||||
head->set_global_position(intersectPoint);
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/Bullet.h>
|
||||
#include <client/ClientWorld.h>
|
||||
#include <client/FirstPersonPlayer.h>
|
||||
#include <client/Main.h>
|
||||
@@ -23,6 +24,7 @@ static void RegisterClasses() {
|
||||
GDREGISTER_ABSTRACT_CLASS(blitz::World);
|
||||
GDREGISTER_CLASS(blitz::ClientWorld);
|
||||
GDREGISTER_CLASS(blitz::ServerWorld);
|
||||
GDREGISTER_CLASS(blitz::Bullet);
|
||||
}
|
||||
|
||||
static void initialize_blitz_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
Reference in New Issue
Block a user