Last active
August 29, 2015 14:15
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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