I’m in the “pen & paper” stage of my platform/action game idea and I’m trying to think of how I am going to do certain things. I came to the topic of explosions and really quickly I just thought of doing simple collision checks with the explosion’s circle and other nearby objects. This sounds like it’d work except when the explosion is near something that blocks it, like a wall. Please excuse my lousy illustrations
Using radius/distance checks, there’s still the problem of the explosion affecting objects on the other side of the wall (see #1 in pic). In most cases, this isn’t desired but could make for some interesting gameplay options (some explosions go through walls while others do not).
In #3, the explosion is being moved out of the wall and then from there, collision checks would be done. This moves the center of the explosion, could confuse the player and if the explosion does any “push”, it wouldn’t be from the spot you’d expect it to be.
Ideally, #2 is how explosions near blocking objects is handled. The explosion and its effects are “chopped” by walls.
http://img440.imageshack.us/img440/9499/14is.th.jpg
(red represents explosion; black line is wall)
To achieve #2, I came up with the idea of “damage lines” that would come out of the center of the explosion.
http://img368.imageshack.us/img368/9122/21ot.th.jpg
(red dot in middle is the origin of the explosion; lines coming out of origin are the damage lines)
Basically, the damage lines would be extended out from the center until they hit a wall or their length is equal to the explosion’s radius. Those lines would be what is checked for collisions with nearby objects.
Each line would do a fraction of the explosion’s max damage. So, using the above pic as an example, the explosion does 80 max damage, each line does 10 damage. This way, objects that are barely inside the explosion radius would touch 1 or 2 lines and only receive 20 damage. An object that was dead center in the explosion would touch every line and get the full 80 damage done to it.
Possible problems with this method is that when the explosion size is a lot bigger than the damagable object size, the explosion can “miss” the object (object small enough to fit between damage lines). More damage lines could remedy that, or just constraining game objects so that case never arises.
Another possible method would be to draw one line from the explosion origin to the object, if that line doesn’t cross any wall and if its length is less than or equal to the explosion’s radius, do some damage on the object. The distance from the explosion center to the object could determine the severity of the damage.
http://img167.imageshack.us/img167/6353/34al1.th.jpg
(red dot is explosion; black dot is out of range, green dot in range but behind wall, blue dot is in range and not blocked, blue dot gets damaged)
The single line idea seems more simple than the previous one, except that it’d need to be done for every object that might be colliding with the explosion: draw line from explosion to nearby object 1, see if it crosses a wall and its length <= radius, repeat for nearby objects 2…n. You’d also need to determine the closest vertex of the object to the explosion or just test every vertex. With the damage line idea, the damage line lengths are determined once based on the nearby walls, and then those resulting lines are collision checked with nearby objects.
Any comments/thoughts/ideas?