Skip to content

Instantly share code, notes, and snippets.

@tiborsimon
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiborsimon/fe3995d70fce3cab327f to your computer and use it in GitHub Desktop.
Save tiborsimon/fe3995d70fce3cab327f to your computer and use it in GitHub Desktop.
Java Shooter Game - Player:: update() - http://tibor-simon.com/programming/auto-aiming-logic-for-games/
...
if (autoAim) {
// determine the rotation direction
float base = image.getRotation();
float d1 = calculateDistance(base, targetAngle);
float d2 = calculateDistance(base-1.0f, targetAngle);
// if the distance is greater than about 3 degree
if (d1 > 0.05f) {
if (d1 > d2) {
turnLeft(delta);
} else {
turnRight(delta);
}
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment