How to do explosion splash damage?



  • I want in game, to have attack that fires large weapon at other group of sprite,
    when weapon hit something, it explode and everything in radius or nearby will take damage, is HaxeFlixel providing way to easily get nearby sprite to explosion without loop through all sprite and check distance?



  • I don't know of an easy way to hurt everything in a radius, but you can make a shrapnel emitter and when you explode the projectile, have it so the particles collide with the victims and put hurt on them if they get hit by a particle. I have a bomb that works this way.



  • FlxG.collide(shrapnel, mobs, bombHit);

    • shrapnel is an emitter of shrapnel particles that emits when the bomb blows up
    • mobs is a FlxGroup of all my enemies
    • bombHit is the function called where I hurt() the mobs that get hit


  • Or for more simple and performance efficient, you can use FlxMath.isDistanceBetween():

    // enemies is a FlxSpriteGroup
    enemies.forEach(damageEnemy);
    
    function damageEnemy(enemy:FlxSprite) {
        if (FlxMath.isDistanceBetween(bomb, enemy, bombRadius)) // SpriteA, SpriteB, Distance
            enemy.hurt()
    }
    

    Note: FlxSpriteGroup::forEach API



  • Thank you @DleanJeans, that was exactly what I need!


Log in to reply