Created
July 11, 2017 22:49
-
-
Save tyler6699/88e832e60a5dd27b3c9e9fdb33438a59 to your computer and use it in GitHub Desktop.
Calculate a vector relative to an objects postion and angle
This file contains hidden or 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
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