feat: damage for beam
This commit is contained in:
parent
317aed8f1b
commit
6ad638c642
10
src/beam.cpp
10
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 <godot_cpp/classes/time.hpp>
|
||||
|
||||
|
@ -15,6 +15,7 @@ void Beam::_enter_tree() { GDGAMEONLY();
|
|||
this->collision_shape = this->get_node<CollisionShape3D>("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<CarPlayer>(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);
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue