The Daily Click ::. Forums ::. Klik Coding Help ::. Enemy zone
 

Post Reply  Post Oekaki 
 

Posted By Message

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
20th May, 2008 at 15:57:03 -


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.

Image Edited by an Administrator.

 
Craps, I'm an old man!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 16:13:10 -

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.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
20th May, 2008 at 16:59:10 -

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.

 
Craps, I'm an old man!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 22:19:13 -

que?

from where?

 
n/a

jbjovi



Registered
  22/07/2007
Points
  41
21st May, 2008 at 01:27:59 -

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 !

Image Edited by the Author.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click