diff --git a/src/hitscan_muzzle.cpp b/src/hitscan_muzzle.cpp index ea15c73..366f937 100644 --- a/src/hitscan_muzzle.cpp +++ b/src/hitscan_muzzle.cpp @@ -4,17 +4,22 @@ #include "utils/godot_macros.hpp" #include #include +#include #include #include +#include +#include void HitscanMuzzle::_bind_methods() { #define CLASSNAME HitscanMuzzle GDFUNCTION(fire); // allow fire() to be called from animation tracks + GDPROPERTY_HINTED(blood_effect, gd::Variant::OBJECT, gd::PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); } void HitscanMuzzle::_ready() { this->set_enabled(false); this->set_physics_process(false); + gd::ResourceLoader::get_singleton()->load(this->blood_effect->get_path()); } void HitscanMuzzle::_physics_process(double) { @@ -26,6 +31,14 @@ void HitscanMuzzle::fire() { this->set_physics_process(true); // offload physics checks to physics process to avoid multithreading issues } +void HitscanMuzzle::set_blood_effect(gd::Ref scene) { + this->blood_effect = scene; +} + +gd::Ref HitscanMuzzle::get_blood_effect() const { + return this->blood_effect; +} + void HitscanMuzzle::fire_physics_check() { this->force_raycast_update(); // since we disabled automatic updating (set_enabled(false) in _ready), we'll have to force update here. gd::Object *hit{this->get_collider()}; @@ -34,4 +47,10 @@ void HitscanMuzzle::fire_physics_check() { DamageableEntity *damage_iface{dynamic_cast(hit)}; if(damage_iface == nullptr) return; // hit object can't be damaged. damage_iface->damage(); + + gd::Vector3 const location{this->get_collision_point()}; + gd::Node3D *effect{gd::Object::cast_to(this->blood_effect->instantiate())}; + this->get_tree()->get_current_scene()->add_child(effect); + effect->set_global_basis(this->get_global_basis()); + effect->set_global_position(location); } diff --git a/src/hitscan_muzzle.hpp b/src/hitscan_muzzle.hpp index 129b028..46138bd 100644 --- a/src/hitscan_muzzle.hpp +++ b/src/hitscan_muzzle.hpp @@ -2,6 +2,7 @@ #define HITSCAN_MUZZLE_HPP #include +#include #include #include #include @@ -15,8 +16,12 @@ public: virtual void _physics_process(double) override; void fire(); // prep a deferred call to fire_physics_check + void set_blood_effect(gd::Ref scene); + gd::Ref get_blood_effect() const; private: void fire_physics_check(); +private: + gd::Ref blood_effect{}; }; #endif // !HITSCAN_MUZZLE_HPP