Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  explosions  (Read 1464 times)
0 Members and 1 Guest are viewing this topic.
Offline sloppyjoe

Junior Newbie





« Posted 2005-12-05 22:40:23 »

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 Cheesy

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.


(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.


(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.


(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?
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2005-12-05 22:47:46 »

I think you might have an easier time just computing the distance of nearby things that can be damaged. Since only characters in the game can usually be damaged, you can simply loop through each of them and find the hypotenuse between the character and the explosion. If the hypotenuse is less than the radius of the explosion, then you know the character has been hurt. As a bonus, you also know how much the character has been hurt.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Vorax

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #2 - Posted 2005-12-05 23:02:33 »

That wouldn't deal with his problem though, things would still get hurt through the wall.

The best solution is a combination of both:  Use the distance to determine which entities can be hurt by the explosion, then fire a ray at each to see if there is anything blocking them from being hurt.  This way you only test collisions for entities that are actually threatened by the explosion.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
kul_th_las
Guest
« Reply #3 - Posted 2005-12-06 00:11:56 »

You might want to look up some stuff on how to do line-of-sight computations (e.g. so you can hide/unhide objects around corners, behind walls,  etc, based on the point of view of characters, or in this case, an explosion).

The two problems deal essentially with the same algorighms, and there's not reason for you not to benefit from others' knowledge.
Offline cylab

JGO Ninja


Medals: 43



« Reply #4 - Posted 2005-12-07 07:30:48 »

Depending on the complexity of your levels and the underlying engine, you could arrange your scenegraph in a manner, that all objects have their "room" as parent node. So you can determine the "room", where the explosion occurs and check the distance of relevant objects in that room in respect to the explosion. If you consider the concept of a "room" and a "wall" a little more abstract this even might work for blocking objects, that are commonly considered inside a room, like closets and such.

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!