Explosion problem

Started by
5 comments, last by Thaumaturge 15 years, 11 months ago
Hi all, I've got a problem creating the explosion when a bullet hits an enemy. (Game is in 2D). I'll draw out the problem: Current explosion: Type: Circular Description: Particles fly in the 6 directions around the enemy. Wanted explosion: When the enemy is hit he explodes, but the particles fly in the 3 directions that go away from the area of impact. Any ideas on how to do this?
Advertisement
Don't send any particles in the 3 directions you don't need?
If you're using a velocity vector of some sort for your bullets, then you could perhaps simply add that to the velocity of the created explosion particles.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

If the six direction are fixed (e.g. they correspond to the vertices of a hexagon), you could do it like this:

1. Create a unit-length vector for each of the six potential directions

2. Normalize the projectile velocity vector

3. Take the dot product of each of the six direction vectors and the velocity vector

4. Sort the direction vectors according to the value of the computed dot products

5. Use the three direction vectors with the highest dot product values
Hold on - I've just realised that you said "away from the area of impact", not "in the direction of the bullet". In that case, if you're comfortable with a circular representation (that is, you're happy with the particles moving away from the point of impact as though they had impacted with a circle):


  • Take the vector between the impacted object and the impact point; we will call this "normal".

  • If you are using six set directions:

    • Use the vector "normal" as jyk suggested you use the projectile velocity vector, or

    • Use an "if" statement to pick the appropriate angles (if angle > 330 or angle < 30, ..., else if angle < 90, ..., etc.).


  • Otherwise, if you are using velocity-based particles (this, admittedly, seems unlikely, given your description, I believe):


    • Add the vector "normal" to the velocity of the created particles.


If you want a more accurate representation, then I would suggest calculating the normal of the impacted object at the point of impact, and using that as I suggested above.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Sorry for being that unclear. I'll try to give a better sketch of the problem.

We now use circular explosions: particles fly in random directions away from the object.

We want backward explosions: particles fly away from the area of impact being the point were the bullet hits the enemy.

sry for the inconvenience and thanks for your time
In that case, I'd suggest either going for my last suggestion above (calculate the normal vector, and add that to the velocity of the created particles), or perhaps this, probably better but also a little more intensive, method:

  • Again, calculate the normal at the point of impact (again selecting from either a circular representation or a more complex one). Normalise this vector if it is not already normalised.

  • Generate your particles as normal, with circularly-distributed velocities.

  • For each particle:
    • Find the scalar projection of the particle's velocity.

    • (Presuming that the normal points out of the impacted object) If thte projection is negative, either:
      • Zero the particle's velocity in this direction, by adding to that velocity -scalar_projection*normal_vector.

      • Reflect the particle's velocity, by adding to that velocity -scalar_projection*2.0*normal_vector


I believe that that should work.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement