ID:1910430
 
(See the best response by Lummox JR.)
Hi All,

Im trying to figure out how to return mobs(or w.e) in a circle.

I have tried hunting around the forums abit so if you can point me to other topics aswell that would help im all ears.


Code:
Attempting to adapt from: http://www.byond.com/forum/?post=1891928
atom/proc/GetCircle(radius = 1)
. = list()
var/rsq = radius * (radius+32)
var/dx, dy, dsq
for(var/atom/a in bounds(src, radius))
dx = a.Cx() - src.Cx()
dy = a.Cy() - src.Cy()
dsq = dx*dx + dy*dy
if(dsq <= rsq) . += a


Absolute positions and DM StdLib in use. (I believe i gain the same results but unsure)

Problem description:
It seems to work for the most part, but i am noticing that its extending and hitting some instances where it (probably) shouldn't be hitting.

Would it be possible for someone to go over this and lend a hand.

Also for extra points ;) how hard is it to get a hitbox to work with diagonal movement, Primarily for standard player attacks (weapon will determine attack range) getting a hitbox to work for North,East,South,West is easy enough with just bounds() but not sure once the player is attacking while facing diagonally.

Best response
That should be radius * (radius+1), not +32. The reason rsq is radius * (radius+1) is that this is the equivalent of (radius+0.5)**2 rounded down. The 32 value makes no sense, which is probably the whole problem.
In response to Lummox JR
Lummox JR wrote:
That should be radius * (radius+1), not +32. The reason rsq is radius * (radius+1) is that this is the equivalent of (radius+0.5)**2 rounded down. The 32 value makes no sense, which is probably the whole problem.

Thanks Lummox, Not quite sure why i changed it to 32 (Guess i thought i had to increase it by a tiles pixel XD)

In any case as you said, that was the problem. Thanks for the help :)
As long as your using circular bounding boxes, the mob will have the same width of hit box from every vector, so you won't have to worry about diagonal hits being easier than cardinal hits.
In response to Kats
Kats wrote:
As long as your using circular bounding boxes, the mob will have the same width of hit box from every vector, so you won't have to worry about diagonal hits being easier than cardinal hits.

The circles were primarily for Explosions, and skills that can give an effect based on the radius (e.g. player uses "lightning shell" everyone within 50 pixels gets hit by lightning every 2secs)

I was planning to have a standard rectangle for the player and have its bounds set (and naturally that would handle collisions to the player).. Then for when the player attacks an object(or simply bounds() altered out from the player) is created to handle the hitbox. I could possibly use the circle aswell for handling the attack (but id only want to check possibly 130Degrees of it)..

I was thinking more in terms of rotating (or calculating a diagonally positioned box) the hitbox so that it returned atoms in that direction as easily as it is to get atoms in NESW.