Skip to content

Instantly share code, notes, and snippets.

@tyler6699
Created July 11, 2017 22:49
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 tyler6699/88e832e60a5dd27b3c9e9fdb33438a59 to your computer and use it in GitHub Desktop.
Save tyler6699/88e832e60a5dd27b3c9e9fdb33438a59 to your computer and use it in GitHub Desktop.
Calculate a vector relative to an objects postion and angle
public Vector2 calculatePosition(float angle, float distance, Vector2 centre) {
float radians = (float) Math.toRadians(angle);
float x = (float) ((Math.cos(radians) * distance) + centre.x);
float y = (float) ((Math.sin(radians) * distance) + centre.y);
return new Vector2(x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment