Public Group

# Help modelling a damage formula requested

This topic is 2640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'd like to ask for some assistance in modelling a simple damage formula, as my math background is pretty rusty.

Basically, I wish to make the player's attack deal vastly higher amounts of damage as the player's health drops into low levels. The player's health starts at 100, and can range from 0-200 based on damage taken and powerups collected during gameplay. With the engine setup that I'm working under, I need to come up with a suitable expression to use as the 'damage' parameter for the player attack function, given access to the 'health' variable which returns the player's current health as an integer.

I've assembled a basic table of values illustrating the general pattern that I want to model regarding the input health vs output damage, as shown by the images below:

- So the attack should be around its normal strength (~2 damage total) when the player has between 70-120 health.

- The attack should become somewhat weaker (~1 damage total) when the player exceeds 120 health.

- The damage should gradually increase as the player moves from 70 health down to around 20 health.

- Below 20 health, the damage should be boosted in a sort of exponential manner, becoming about twenty times (or more) greater than normal by the time the player is drained to 5 health.

My grasp of mathematical functions is not great, so I've had a difficult time getting anything to approximate this type of desired pattern.
The best I've managed is a laughably simple quadratic equation of the form y= -(0.01) x[sup]2[/sup] + 40, where y represents the damage and x represents the player's health. This translates into my code in a manner like follows, simplified for clarity:

F_PlayerAttack (-0.01 * (health)^2 + 40); 
However, this model/expression is horridly inadequate, as it doesn't really match up with the desired damage values for anything above 50 health, dipping into negatives quickly. I'm skeptical about whether a quadratic function is really a good way to be going about this at all, but I don't know how to approach the problem better. Can I use some constant values or something to keep the general contour of my above graph, without losing either the parabolic shape or the flatness of everything else? Would cubic/quartic functions be a better way to model this type of thing, and if so, can I get some pointers on how to apply them? Should I play around with inverse functions?

I've been running into a bit of a brick wall on this for the past couple days, so it seems like I could use a little help from more experienced minds.
Now in case anyone is about to tell me that I'd have an easier time coding the damage changes into the health system or adding code to check the health and broadly adjust it before dealing damage, that type of thing is already out of the question in my case, as none of te deeper code is mine to modify. I'm just looking for an expression which at least roughly models the intended damage vs health pattern.

Thanks in advance for any assistance. =)

##### Share on other sites
Your curve reminds me of this shape.

So my suggestion would be to play with the site I used to generate that graph and see if you can plug in minor variations on that equation (y = 1 + 1/(x^2)) to get the values you want. If you prefer something you can download that'll be a little more powerful and a bit faster, check out Graphmatica.

##### Share on other sites
Wow, thanks for the quick reply. This equation is just the sort of thing I was hoping for, I appreciate it.

##### Share on other sites
Here's what I got after messing around with the site that Apoch recommended:

http://www.quickmath...=200&v4=0&v5=50

EDIT: This one seems to match your criteria a little better...

http://www.quickmath.com/webMathematica3/quickmath/graphs/equations/basic.jsp#v1=y%3D%2823000%2F%28%28x+%2B+23%29%5E2%29%29&v2=0&v3=200&v4=0&v5=50

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013639
×