From f405c37daccac93323081216b2484da498e2fecf Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Thu, 12 Apr 2018 21:27:07 +0200 Subject: Tracing vs entities, bullets can now hit. --- src/game/unit_soldier.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/game/unit_soldier.cpp') diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index e44e8a2..b3e93d1 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -84,7 +84,7 @@ void unit_soldier_t::shoot(v2f_t aim) end = x + (aim - x).norm() * 40; - trace = world->ray_v_all(x, end, CF_SOLID, this); + trace = world->ray_v_all(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, this); muzzle_point = x + v2f_t(0, -1.0f); @@ -95,8 +95,15 @@ void unit_soldier_t::shoot(v2f_t aim) flash->place(&game->world); last_attack = game->now; + assets::soldier.fire.play_3d(x); - //target->damage(3, this); FIXME + + if (trace.hit && trace.ent) { + if (trace.ent->type == ET_UNIT) { + unit_t *unit = dynamic_cast(trace.ent); + unit->damage(3, this); + } + } } void unit_soldier_t::target_and_attack(void) @@ -127,7 +134,7 @@ skip_targetting: if (last_attack + game->prng.next_float(1.4f, 1.6f) > game->now) return; - shoot(spread_aim(aim, 0.2, &game->prng)); + shoot(spread_aim(aim, 0.01, &game->prng)); } void unit_soldier_t::on_think(void) -- cgit