By the way, ghosts sometimes fail to detect the crosshair when they are close to 0°. This may help (or the equivalent for your programming language).
#include <math.h> /* Reminder between two floats in C. * This is equivalent to the "%" operand between floats in Python. * fmodf(a, b) isn't enough because in C, the modulo operation * retrieves negative values for negative operands. */ float fremf(float a, float b) { float r = fmodf(a, b); return r < 0 ? r + b : r; } /* Change required in the current_angle to become the target_angle, * accounting for revolutions. Results in the range [-PI, PI). * Useful for objects tracking enemies. */ float angle_delta(float current_angle, float target_angle) { current_angle = fremf(current_angle, 2*M_PI); target_angle = fremf(target_angle, 2*M_PI); float delta = target_angle - current_angle; if (delta < -M_PI) return 2*M_PI + delta; if (delta > M_PI) return delta - 2*M_PI; return delta; }
Leave a comment
Log in with itch.io to leave a comment.