How do I use a "Resistence" Mechanic to reduce damage?

0 favourites
  • 4 posts
From the Asset Store
This sound pack features 117 game sounds : Axe,Punch Swing & Hit & Damage. This is a perfect collection for your game.
  • Currently i'm using instance variables in a formula like this:

    (Hero.damage - Enemy.Defense) <-- That's in the event to "subtract from the instance variable" (HP) of the enemy.

    The problem is, when the damage dealt is less than the Enemy's Defense, the HP from the enemy goes up, kinda like the attack is healing the enemy... I need to make so the resistance reduces de damage to 0 at the worst scenario, but never heals the enemy from the attacks the player makes.

    There is a tool or some kind of trick to make a mechanic like that work?

  • Compare Enemy Defense and Hero Damage

    If Enemy Defense >= Hero Damage

    - Do nothing or just show "miss"

    Else

    - Subtract enemy HP

  • What klabundee suggested will work

    There's also a system expression that's great for this called clamp()

    You would do

    Clamp(hero damage - enemy defense, 0, infinity)

    This would make it so the damage never goes below 0 and never goes higher than infinity

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Both above solutions will work.

    The way I would do is simply use the 'max' system expression.

    hp = max(0, Hero.damage - Enemy.Defense)

    this way, it will take the maximum value from the two parameters. Which means, when the subtraction goes negative, it will choose 0 as hp.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)