From f8496d3d48beeb6e0c5ef8dc82e16d281c94148e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 7 Jan 2025 10:05:58 +0100 Subject: add collider to zapper --- game/prefab/ZapperObject.cpp | 11 +++++++++++ game/prefab/ZapperObject.h | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'game/prefab') diff --git a/game/prefab/ZapperObject.cpp b/game/prefab/ZapperObject.cpp index fcc6467..f70415c 100644 --- a/game/prefab/ZapperObject.cpp +++ b/game/prefab/ZapperObject.cpp @@ -73,6 +73,15 @@ ZapperObject::ZapperObject(crepe::GameObject && base) .glow_end = add_component( sprite.glow_end, ivec2(128, 128), uvec2(16, 1), animator.glow_start.data ), + }, + body { + add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .kinematic_collision = false, + }) + }, + collider { + add_component(vec2(0, 0)) } { this->place(this->transform.position, 0, 300); } @@ -89,5 +98,7 @@ void ZapperObject::place(const crepe::vec2 & position, float rotation, float len this->sprite.glow_end.data.position_offset = -offset; this->sprite.beam.data.size.x = length; + + this->collider.dimensions = offset.rotate(rotation) * 2 + vec2(30, 30) * SCALE; } diff --git a/game/prefab/ZapperObject.h b/game/prefab/ZapperObject.h index b4bb942..c43af67 100644 --- a/game/prefab/ZapperObject.h +++ b/game/prefab/ZapperObject.h @@ -26,8 +26,8 @@ public: crepe::Animator & glow_end; } animator; - // crepe::Rigidbody & body; - // crepe::BoxCollider & collider; + crepe::Rigidbody & body; + crepe::BoxCollider & collider; private: static constexpr float SCALE = 0.8; -- cgit v1.2.3