From ff5dfab94de1eaeaa021bbc938b0956d6d3195a2 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 21 May 2026 10:37:23 +0200 Subject: [PATCH] =?UTF-8?q?tune(bullet):=20empuje=20cuasi-f=C3=ADsico=20(m?= =?UTF-8?q?omento=20real=20de=20la=20bala)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sustitueix IMPACT_IMPULSE (magnitud arbitrària radial) per IMPACT_MOMENTUM_FACTOR (factor de transferència del moment de la bala). El impulse ara és bullet.body.velocity * (bullet.body.mass * factor), és a dir el moment lineal real de la bala, dirigit cap a on viatjava. Amb factor=1.0 i la bala (m=0.5, v=700 px/s): - Pentagon (m=5) → Δv = 70 px/s (doble de la seva velocity base) - Quadrat (m=8) → Δv = 44 px/s - Molinillo (m=4) → Δv = 88 px/s Visiblement notable durant el segon de "ferit" abans de l'explosió. El factor és tunable per pujar/baixar segons gusts. Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/defaults/physics.hpp | 5 ++++- source/game/systems/collision_system.cpp | 16 ++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/source/core/defaults/physics.hpp b/source/core/defaults/physics.hpp index 0f4ec3b..f6f5dad 100644 --- a/source/core/defaults/physics.hpp +++ b/source/core/defaults/physics.hpp @@ -11,8 +11,11 @@ namespace Defaults::Physics { constexpr float FRICTION = 20.0F; // px/s² // Bullet — impacto físico contra enemigo (impulse mass-aware). + // Model: el impulse és el moment lineal de la bala (m·v) multiplicat per + // un factor de transferència [0..1]. 1.0 = transfereix tot el moment + // (col·lisió perfectament inelàstica), 0.5 = transfereix la meitat. namespace Bullet { - constexpr float IMPACT_IMPULSE = 50.0F; // Magnitud del impulse en la dirección bullet→enemy + constexpr float IMPACT_MOMENTUM_FACTOR = 1.0F; // Factor de transferència de moment bala→enemic } // namespace Bullet // Explosions (debris physics) diff --git a/source/game/systems/collision_system.cpp b/source/game/systems/collision_system.cpp index a65e862..a26b7fe 100644 --- a/source/game/systems/collision_system.cpp +++ b/source/game/systems/collision_system.cpp @@ -87,16 +87,12 @@ namespace Systems::Collision { } // *** COLISIÓN bullet → enemy *** - // Empuje físico: impulse en la dirección bullet→enemy (fallback a la - // dirección de la bala si están exactamente solapados). - Vec2 normal = enemy.getCenter() - bullet.getCenter(); - if (normal.lengthSquared() > 0.000001F) { - normal = normal.normalized(); - } else { - const Vec2 BVEL = bullet.getBody().velocity; - normal = (BVEL.lengthSquared() > 0.0F) ? BVEL.normalized() : Vec2{.x = 0.0F, .y = -1.0F}; - } - enemy.applyImpulse(normal * Defaults::Physics::Bullet::IMPACT_IMPULSE); + // Empuje físico cuasi-realista: el impulse és el moment de la bala + // (m·v) multiplicat pel factor de transferència. Direcció = vector + // velocity de la bala (cap a on viatjava). + const Vec2 IMPULSE = bullet.getBody().velocity * + (bullet.getBody().mass * Defaults::Physics::Bullet::IMPACT_MOMENTUM_FACTOR); + enemy.applyImpulse(IMPULSE); const uint8_t SHOOTER = bullet.getOwnerId();