• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

damage help

ban885

Member
hey guys, im currently working on a game and im having an issue calculating some damage, like i want to deal a percentage hp damage but i have no clue how to do this, i've tried like "hp-=.25*hp" i've looked almost everywhere but here. some if i could get some assistance that would be great thanks .
 
K

Khanon

Guest
try
Code:
hp*=0.75

you have '+=' , '-=' ... but also '/=' and '*=' when you manipulate variable ...
have fun
 
M

Mandarieno

Guest
You could do the calculation like this

Code:
hp -= hp / 100 * 50;
This subtracts 50% from the hp value.

EDIT* Actually can you give us more context on what happens in your event? I don't think your calculation is the problem.
 
Last edited by a moderator:

ban885

Member
You could do the calculation like this

Code:
hp -= hp / 100 * 50;
This subtracts 50% from the hp value.

EDIT* Actually can you give us more context on what happens in your event? I don't think your calculation is the problem.
i don't know it just seems off, like doing hp*=0.75 puts the hp at exactly 75 hp. like it doesn't feel right. sorry its hard to explain... um so like if you ever play league of legends. they have base hp damage like doing 2% of a character hp. but instead i feel like its just taking the damage from the current hp, instead of the whole thing.
 
L

Lars Karlsson

Guest
You need to keep track of their max hp. So it'd be something like:
Code:
hp -= max_hp * 0.02;  // Take 2% damage
 
Top