Last active
October 16, 2017 20:14
-
-
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
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
// 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