From 6ad638c642b3b665af04edb5d6f29e990d0091cb Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 21 May 2024 15:59:26 +0200 Subject: [PATCH] feat: damage for beam --- src/beam.cpp | 10 ++++++++-- src/beam.hpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/beam.cpp b/src/beam.cpp index 200050b..0801ad4 100644 --- a/src/beam.cpp +++ b/src/beam.cpp @@ -1,5 +1,5 @@ #include "beam.hpp" -#include "godot_cpp/variant/utility_functions.hpp" +#include "car_player.hpp" #include "utils/godot_macros.h" #include @@ -15,6 +15,7 @@ void Beam::_enter_tree() { GDGAMEONLY(); this->collision_shape = this->get_node("CollisionShape3D"); if(this->collision_shape) this->shape = this->collision_shape->get_shape(); + this->connect("body_entered", callable_mp(this, &Beam::body_entered)); } void Beam::_process(double delta_time) { GDGAMEONLY(); @@ -23,12 +24,17 @@ void Beam::_process(double delta_time) { GDGAMEONLY(); } } +void Beam::body_entered(Node3D *node) { + CarPlayer *player = Object::cast_to(node); + if(player) player->damage(); +} + void Beam::set_from_to(Vector3 from, Vector3 to) { Vector3 const z = (to - from).normalized(); Vector3 const x = z.cross({0.f, 1.f, 0.f}).normalized(); double const length = (from - to).length(); - this->set_global_position(from + z * (length / 2.f + 3.f)); + this->set_global_position(from + z * (length / 2.f + 1.f)); this->set_global_basis({x, z.cross(x).normalized(), z}); if(this->mesh.is_valid()) this->mesh->set_height(length); diff --git a/src/beam.hpp b/src/beam.hpp index c6c71fc..c7705c4 100644 --- a/src/beam.hpp +++ b/src/beam.hpp @@ -16,6 +16,7 @@ class Beam : public Area3D { public: virtual void _enter_tree() override; virtual void _process(double delta_time) override; + void body_entered(Node3D *node); void set_from_to(Vector3 from, Vector3 to); void set_end_time(float time_from_now); private: