Jump to content
  • Advertisement
Sign in to follow this  
Metzger

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.

If you intended to correct an error in the post then please contact us.

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:


table1q.png table2a.png


- 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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!