Distance of player vs. enemy math?

DrGlickertDrGlickert Member Posts: 1,135
edited November -1 in Working with GS (Mac)
Is this right?

I'd like to have the player shoot enemies (easy). BUT, I want the distance between the player and the enemy to be a factor (closer to enemy = increased chance of hitting the enemy).

To find the distance between the player and the enemy is this math right?

Player (X,Y) is (240, 160) ... 240 + 160 = 400

Enemy (X,Y) is (231,280) ... 231 + 280 = 511

So the difference between 400 and 511 is 111, so the distance between the player and the enemy is 111 pixels? (I would use the absolute value so the number would always be positive).

But is this math correct? Am I on the right track here?

Comments

Sign In or Register to comment.