Created
June 13, 2023 19:00
-
-
Save ElPresidentePoole/7a6e88da0d68186a8c15f2c716b0d029 to your computer and use it in GitHub Desktop.
Get Vector Towards Position
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
#include <math.h> // include this at the top of your .c file | |
Vector2 get_vector_towards_position(Vector2 from, Vector2 to) { | |
int dx = from.x - to.x; | |
int dy = from.y - to.y; | |
double angle_between_points = atan2(dy, dx); | |
return (Vector2){-cos(angle_between_points), -sin(angle_between_points)}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment