Page 1 of 1

[Rseding91] [0.14] AoE works against entity center instead of collision

Posted: Wed Apr 12, 2017 4:49 pm
by Mooncat
Bug:
Area-of-effect in the game works against the center point of each entity.
This leads to undesired result when a small AoE is used against an entity with large collision box.
The follow GIF shows the problem:
GIF

Steps to reproduce:
1) Download the following mod.
aoe-works-on-center-only_0.0.1.zip
(978 Bytes) Downloaded 111 times
It scales up the iron chest, and makes wooden chest, iron chest and grenade free to make.
(The collision box of iron chest is slightly updated after recording that GIF)
(Rocket silo may also do the trick)

2) Start a game. Place an iron chest. Maybe place some wooden chests for comparison.

3) Get yourself some grenades. Throw them near the iron chest and observe.


Expected:
Area-of-effect is applied according to collision detection. Grenade should be able to damage the iron chest whenever its area hits the collision box of the chest.

Re: [0.14] AoE works against entity center instead of collision

Posted: Wed Apr 12, 2017 5:38 pm
by Loewchen
This looks more like an intended simplification than a bug to me.

Re: [0.14] AoE works against entity center instead of collision

Posted: Wed Apr 12, 2017 5:45 pm
by Mooncat
Loewchen wrote:This looks more like an intended simplification than a bug to me.
I know performance is considered. But I think it is not a common approach in games?
You can see the problem with grenade vs rocket silo. So it is not just about mod.
I'd let the devs to decide whether fix it or not. :)

Re: [0.14] AoE works against entity center instead of collision

Posted: Thu Apr 13, 2017 11:19 am
by orzelek
It would also count (on smaller scale most likely) when throwing grenades near biter spawners. So could be visible by just playing game.

Re: [0.14] AoE works against entity center instead of collision

Posted: Fri Apr 14, 2017 11:05 am
by Rseding91
This isn't a bug so much as "not working how might be desired". The AoE was programmed to specifically check distance from entity position (entity center) so it's working as programmed. The AoE trigger is what you describe: distance from center point of entity. Most entities have square bounding boxes so when an entity is large you can see the "distance from center" logic happening far easier.

Now, even though it's not a bug it would still be useful to have it capable of working against the collision boxes of entities instead of the entity position. I'll see what can be done.

Re: [0.14] AoE works against entity center instead of collision

Posted: Fri Apr 14, 2017 11:51 am
by Engimage
Rseding91 wrote:This isn't a bug so much as "not working how might be desired". The AoE was programmed to specifically check distance from entity position (entity center) so it's working as programmed. The AoE trigger is what you describe: distance from center point of entity. Most entities have square bounding boxes so when an entity is large you can see the "distance from center" logic happening far easier.

Now, even though it's not a bug it would still be useful to have it capable of working against the collision boxes of entities instead of the entity position. I'll see what can be done.
Actually that is pretty simple - you got to test all four corners of the entity as opposed to center one which will be almost ideal. 8 points is nearly perfect but thats a bit too much.
As an alternative you might calculate entity "radius" (despite being square) and measure distance between explosion center and entity center with the sum of radii of entity and explosion.

Re: [0.14] AoE works against entity center instead of collision

Posted: Thu Apr 20, 2017 12:07 pm
by SyncViews
PacifyerGrey wrote:Actually that is pretty simple - you got to test all four corners of the entity as opposed to center one which will be almost ideal. 8 points is nearly perfect but thats a bit too much.
Actually, if you have an axis aligned rectangle (say centered at (rx,ry) of size (rw,rh)) and want the distance from a point (px,py) to the nearest edge (0 for "inside") you can just calculate it. There are similar ways for various shapes (including rotated rectangles, or getting the intersection coordinates, etc.), and most applies to both 2D and 3D.

Code: Select all

//abs(px - rx) will give distance on that axis to the centre. -rw/2 along with max converts that to the edge on that axis or 0 for inside.
dx = max(abs(px - rx) - rw/2, 0)
dy = max(abs(py - ry) - rh/2, 0)
//so now squared distance between
distanceSqr = dx*dx + dy*dy
//generally for most purposes, distance squared is desired anyway, square root is expensive (doing "distanceSqr <= radius*radius" is cheaper and could potentially be precomputed and cached)
distance = sqrt(distanceSqr)

Re: [Rseding91] [0.14] AoE works against entity center instead of collision

Posted: Sun Oct 22, 2017 7:16 pm
by Rseding91
I've changed this for 0.16 so the AoE check works against the bounding box instead of the center position.