Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. public void lookAt(float x, float y) {
  2. final float tolerance = (float) Math.PI / 9;
  3. final float angle = (float) (Math.atan2(y, x) - Math.PI / 2);
  4. if (physics.getRotation() <= angle + tolerance && physics.getRotation() >= angle - tolerance) {
  5. physics.setRotation(angle);
  6. } else if (physics.getRotation() > angle + tolerance) {
  7. physics.setAngularVelocity(-15);
  8. } else if (physics.getRotation() < angle - tolerance) {
  9. physics.setAngularVelocity(15);
  10. }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement