From ea9b201a08952abeb4c3de3afe5a53ca2457b57a Mon Sep 17 00:00:00 2001 From: DavoSK Date: Thu, 2 Feb 2023 19:22:12 +0100 Subject: [PATCH] proper pos offset --- code/games/survival/src/system_weapon.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/code/games/survival/src/system_weapon.c b/code/games/survival/src/system_weapon.c index 2c6b816..dbc7b5d 100644 --- a/code/games/survival/src/system_weapon.c +++ b/code/games/survival/src/system_weapon.c @@ -38,16 +38,16 @@ void WeaponKnifeMechanic(ecs_iter_t *it) { .y=input[i].hy*WEAPON_PROJECTILE_SPEED*-1 }); - Position *dest = ecs_get_mut(world_ecs(), e, Position); - const float offset = get_rand_between(-WEAPON_PROJECTILE_POS_OFFSET, WEAPON_PROJECTILE_POS_OFFSET); - dest->x=pos[i].x; - dest->y=pos[i].y; + zpl_vec2 input_vec = { + .x = input[i].hy, + .y = input[i].hx + }; - if(zpl_abs(input[i].hx) > 0) - dest->y += offset; - - if(zpl_abs(input[i].hy) > 0) - dest->x += offset; + zpl_vec2 pos_offset; + zpl_vec2_mul(&pos_offset, input_vec, get_rand_between(-WEAPON_PROJECTILE_POS_OFFSET, WEAPON_PROJECTILE_POS_OFFSET)); + Position *dest = ecs_get_mut(world_ecs(), e, Position); + dest->x = pos[i].x + pos_offset.x; + dest->y = pos[i].y + pos_offset.y; } weapon[i].spawn_delay = WEAPON_KNIFE_SPAWN_DELAY;