Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (565)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (606)
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 1540 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 Devvie

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
« 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: 78

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

theagentd (13 views)
2015-03-27 23:08:20

wxwsk8er (54 views)
2015-03-20 15:39:46

Fairy Tailz (47 views)
2015-03-15 21:52:20

Olo (29 views)
2015-03-13 17:51:59

Olo (32 views)
2015-03-13 17:50:51

Olo (39 views)
2015-03-13 17:50:16

Olo (44 views)
2015-03-13 17:47:07

ClaasJG (58 views)
2015-03-10 11:36:42

ClaasJG (42 views)
2015-03-10 11:33:01

Pippogeek (50 views)
2015-03-05 14:36:23
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27 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‑
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!