From 8fd896e1ca1a9da8a3083e558ed692d44bf53bd7 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:33:10 +0200 Subject: [PATCH] [MIRROR] Fixes projectiles facing north if ricocheting, deflected or homing (#29057) * Fixes projectiles facing north if ricocheting, deflected or homing (#85216) ## About The Pull Request It **turns** out that `TurnTo` doesn't re**turn** `Turn`, but the angle (number, not matrix) it's **turn**ed to (used nowhere in the code), and `transform` is built-in variable that default to an identity matrix if set to an invalid value (anything but another matrix) The only thing keeping the projectiles facing the right direction when fired up to one of the aforementioned situations was another `Turn` call (not `turnTo`) called on `projectile/fire`, which I apparently didn't fully grasp the redundancy of (if there were no such issue to begin with) at the time. This PR also cleans up and rearranges the related code a little, including a fallback that was never reached because the projectile `Angle` variable is never null (unless something theorically fucky wucky happens with projectile code but that'd be an even bigger issue). ## Why It's Good For The Game Fixing an old issue caused by the author of this PR in #80599, me. ## Changelog :cl: fix: Fixes projectiles facing north if ricocheting, deflected or homing /:cl: * Fixes projectiles facing north if ricocheting, deflected or homing --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> --- code/__HELPERS/matrices.dm | 3 +-- code/modules/projectiles/projectile.dm | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/code/__HELPERS/matrices.dm b/code/__HELPERS/matrices.dm index 68b94fc2fe6..8a5534e3827 100644 --- a/code/__HELPERS/matrices.dm +++ b/code/__HELPERS/matrices.dm @@ -40,8 +40,7 @@ decompose_matrix.rotation = arctan(cossine, sine) * flip_sign /matrix/proc/TurnTo(old_angle, new_angle) - . = new_angle - old_angle - Turn(.) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT + return Turn(new_angle - old_angle) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT /** * Shear the transform on either or both axes. diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index b9622e47c8b..6390fb2e1a9 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -84,7 +84,8 @@ /// `speed` a modest value like 1 and set this to a low value like 0.2. var/pixel_speed_multiplier = 1 - var/Angle = 0 + /// The current angle of the projectile. Initially null, so if the arg is missing from [/fire()], we can calculate it from firer and target as fallback. + var/Angle var/original_angle = 0 //Angle at firing var/nondirectional_sprite = FALSE //Set TRUE to prevent projectiles from having their sprites rotated based on firing angle var/spread = 0 //amount (in degrees) of projectile spread @@ -811,21 +812,19 @@ process_hit(get_turf(direct_target), direct_target) if(QDELETED(src)) return + var/turf/starting = get_turf(src) if(isnum(angle)) set_angle(angle) - if(spread) - set_angle(Angle + ((rand() - 0.5) * spread)) - var/turf/starting = get_turf(src) - if(isnull(Angle)) //Try to resolve through offsets if there's no angle set. + else if(isnull(Angle)) //Try to resolve through offsets if there's no angle set. if(isnull(xo) || isnull(yo)) stack_trace("WARNING: Projectile [type] deleted due to being unable to resolve a target after angle was null!") qdel(src) return var/turf/target = locate(clamp(starting + xo, 1, world.maxx), clamp(starting + yo, 1, world.maxy), starting.z) set_angle(get_angle(src, target)) + if(spread) + set_angle(Angle + (rand() - 0.5) * spread) original_angle = Angle - if(!nondirectional_sprite) - transform = transform.Turn(Angle) trajectory_ignore_forcemove = TRUE forceMove(starting) trajectory_ignore_forcemove = FALSE