diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 23c7a9f2dc08..194db09bede8 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -99,6 +99,7 @@ var/atom/movable/big_subject = subject . += (big_subject.bound_height - world.icon_size) / 2 +/// Calculate the angle between two atoms. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc. /proc/Get_Angle(atom/start, atom/end)//For beams. if(!start || !end) return 0 @@ -112,14 +113,14 @@ return 0 //Atoms are not on turfs. var/dy = get_pixel_position_y(end) - get_pixel_position_y(start) var/dx = get_pixel_position_x(end) - get_pixel_position_x(start) - . = arctan(dy, dx) + return delta_to_angle(dx, dy) + +/// Calculate the angle produced by a pair of x and y deltas. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc. +/proc/delta_to_angle(dx, dy) + . = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc. if(. < 0) . += 360 -/proc/Get_Pixel_Angle(dx, dy)//for getting the angle when animating something's pixel_x and pixel_y - var/da = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc. - return (da >= 0 ? da : da + 360) - /proc/angle_to_dir(angle) switch(angle) //diagonal directions get priority over straight directions in edge cases if (22.5 to 67.5) diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index f44da069c917..a473c06b2b9d 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -245,7 +245,7 @@ var/dx = p_x + aim_turf.x * 32 - source_turf.x * 32 // todo account for firer offsets var/dy = p_y + aim_turf.y * 32 - source_turf.y * 32 - angle = Get_Pixel_Angle(dx, dy) + angle = delta_to_angle(dx, dy) /obj/projectile/process(delta_time) . = PROC_RETURN_SLEEP @@ -287,7 +287,7 @@ //Change the bullet angle to its visual path - var/vis_angle = Get_Pixel_Angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source) + var/vis_angle = delta_to_angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source) var/matrix/rotate = matrix() rotate.Turn(vis_angle) apply_transform(rotate)