How do I turn value into % ?

0 favourites
  • 11 posts
From the Asset Store
A well commented RPG game template to learn from or use as a base for your own game!
  • Greetings there! ^_^

    So i am designing an armor system as a string value. When being hit, i want to reduce the dmg by the value of the armor in %

    • Let's say damge is 50 and armor is 20, i want the damage to be reduced by armor in % and not flat out 20.

    Is there some way to do this?

    Player in collission with Bullet, substract from player health 20-Player.armor (this will be flat out 20, but i want the 20 to be %, how to do this?)

    Thanks in advance!

  • [armor] - [dmg] * multiplier

    Set the multiplier to 0.2 to only use 20% of the damage.

    Use 0.5 to use 50%.

  • [armor] - [dmg] * multiplier

    Set the multiplier to 0.2 to only use 20% of the damage.

    Use 0.5 to use 50%.

    Im sorry what? That does not make any sense to me, sorry.

    Basically when Player is in colission with bullet -

    Subsctract Damage - Armor from Health

    If armor is the value of 20, i wanna turn it into 20%

    So if Damage is 100, it should be 100-20% = 80 dmg from health

  • round(value / value) * 100

    round(55 / 80) * 100 = 69%

    edit: if you want the value from the percentage:

    (percentage / 100) * value

    round(69 / 100) * 80 = 55

  • round(value / value) * 100

    round(55 / 80) * 100 = 69%

    Im sorry what? That explains nothing... Like seriously i know u guys trying to help but ur not making sense at all.

    My Code is, ''Substract From ''Health''; Damage - armor''

    Health = 150

    Damage = 60

    Armor = 20

    I want the code above to deal 60 dmg - 20% (armor.)

    I cant make it a constant 20% since armor will vary..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Divide by 100 to get percent. (20/100 = 0.2 AKA 20%)

    multiply result to get percentage (0.2 * 60 = 12 AKA 20% of 60)

    subtract percentage from self (60-12 = 48 AKA 60 dmg - 20% (armor))

    subtract result from health (150 - 48 = 102)

    Health - (Damage - Damage * Armor/100)

    150 - (60 - 60 * 20/100) = 102

  • Ninja'd, but anyway:

    To get 20% of something, you multiply it by 0.2 (that is 20/100).

    So assuming I understand, if damage is 60, but you want to reduce it by 20%, 60 * 0.2 = 12, so 60 - 12 = 48 (adjusted damage). What was being pointed out above, is that you can do it simpler by multiplying by 100%-20% = 80%. So 60 * 0.8 = 48.

  • Ninja'd, but anyway:

    To get 20% of something, you multiply it by 0.2 (that is 20/100).

    So assuming I understand, if damage is 60, but you want to reduce it by 20%, 60 * 0.2 = 12, so 60 - 12 = 48 (adjusted damage). What was being pointed out above, is that you can do it simpler by multiplying by 100%-20% = 80%. So 60 * 0.8 = 48.

    Hey i dont understand what he is trying to say honestly, maybe u can help? ^_^

    I know the counting but i cant use the above to get the code.

    Health = 150

    Damage = 60

    Armor = 20

    So the code is, when hit, *Substract from Health* = ?? what? How to do it using variables of the above?

    Becuase if armor was 0.2 instead of 20, then using = Damage * Armor - Damage will become a negative number.

  • Divide by 100 to get percent. (20/100 = 0.2 AKA 20%)

    multiply result to get percentage (0.2 * 60 = 12 AKA 20% of 60)

    subtract percentage from self (60-12 = 48 AKA 60 dmg - 20% (armor))

    subtract result from health (150 - 48 = 102)

    Health - (Damage - Damage * Armor/100)

    150 - (60 - 60 * 20/100) = 102

    Yeah that does not work because we cant willy nilly pick any number, the armors are fixed Variables. Try to do it with these variables instead -

    Health = 150

    Damage = 60

    Armor = 20

    Now go. When hit, *Substract from Health* = ???

    Your part above, go show me - The armor on each target vill vary and not be the same, so we cant use random numbers in the code, must be Damage and Armor and Health.

  • Health - (Damage - Damage * Armor/100)

    must be Damage and Armor and Health.

  • > Health - (Damage - Damage * Armor/100)

    >

    > must be Damage and Armor and Health.

    >

    Isn't it faster if we set Armor = 0.8

    And just do Damage * Armor? - Shorter code no?

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