Skip to content

Instantly share code, notes, and snippets.

@PsichiX
Last active October 16, 2017 20:14
Show Gist options
  • Save PsichiX/f08c067042efa055ab66eafe7281b2d7 to your computer and use it in GitHub Desktop.
Save PsichiX/f08c067042efa055ab66eafe7281b2d7 to your computer and use it in GitHub Desktop.
[GML] Calculate if enemy is on the right or right side of our instance
// calcualte position difference (a.k.a. tangent vector):
var dx = enemy.x - x;
var dy = enemy.y - y;
// calculate angle in radians of instance:
var rad = degtorad(image_angle);
// calculate where is instance right side (a.k.a. binormal vector):
var bx = -sin(rad);
var by = cos(rad);
// calculate on which side of instance enemy is (1 - on the right; 0 - directly in front; -1; on the left):
var side = sign(dot_product(dx, dy, bx, by));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment