Skip to content

Instantly share code, notes, and snippets.

@ElPresidentePoole
Created June 13, 2023 19:00
Show Gist options
  • Save ElPresidentePoole/7a6e88da0d68186a8c15f2c716b0d029 to your computer and use it in GitHub Desktop.
Save ElPresidentePoole/7a6e88da0d68186a8c15f2c716b0d029 to your computer and use it in GitHub Desktop.
Get Vector Towards Position
#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