On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits) (+1)

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;
}
(1 edit) (+1)

Python makes it look easy.

from math import pi
def angle_delta(current_angle, target_angle):
    current_angle %= 2*pi
    target_angle %= 2*pi
    delta = target_angle - current_angle
    if delta < -pi :
        return 2*pi + delta;
    if delta > pi :
        return delta - 2*pi
    return delta
(+1)

Es cierto, Lo acabo de revisar. Muchas gracias :D