Originally Posted by cecil sadly shabs only works for the x distance. but can be modified slightly to work in an x AND y situation.
dont use
- Player is in a range of + or -250 pixels (depending on the position of player relative to the enemy) from the enemy (X axis)
- Player is in a range of -10 to +10 pixels from the enemy (Y axis)
because that makes a square which doesnt accurately depict distance. the enemy could be +10 and 250 away which is farther than 0 and 250. its just not good practice.
use a distance formula to put the distance of the enemy from the player into an alterable.
distance^2 = x^2 + y^2
distance = sqrt(x^2 + y^2)
x would be the x distance between enemy and player, and y would be y distance between enemy and player. that formula gives you the distance in between based on their x's and y's.
simply compare the distance to a fixed value to check if its close enough.
Uh no, it works for Y as well. I'll upload the example when I get home. You just do the same exact thing for Y and add it in the same event. Yeah, it's only for a box though.
thats what i was meaning. you either do it for x or for y. not both in the same. thats how i used to do enemy zones and distance. its just not good, its horribly innacurate, unless youre really wanting a box zone area.
Well technically a box include both X and Y, but I get what you mean. Yeah, it whatever I used this for (pre Aru Core I think) it didn't matter if it was a box.
Ok, with the picture I understand what you mean now.
And you're right, the zone created by your method is more logical than mine. Except that I'm working on a platform game, and the square is good in that case (the enemy I'm working on precisely). But I'm curious to see a short exemple of your method cause I'm planning to have flying enemies, and in this case, your method will be better.
This subject would be a good subject for a tutorial I think...
EDIT : I asked an exemple because I don't know what mean ^ and sqrt in math... Sorry I'm 35 years old, school is far away from me !