Please help me find a simple formula to...

320972ee50b8accc932e55c92a9683c5
0
BlinkerGuy 101 Jun 08, 2005 at 05:22

When making an FPS game, there is something called armor which reduces the damage for the health.

Example:

Armor=100
Health=100

Rain gun damage=100

Result after the raingun damage:

Armor=33
Health=66

Anyone? I spent hours doing a google search for it but came out empty handed.

4 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Jun 08, 2005 at 06:33

Just have some percentage of the damage hit armor, and the rest hit health.

You can vary the percentage based on the level of armor, so that for example when you have 100 armor, 100% of the damage is recieved by the armor, but when you have 0 armor, 100% of the damage is recieved by the health.

Bf709252753056976649bf6106ddab41
0
justdan 101 Jun 27, 2005 at 21:15

It could also depend where you get hit, what kind of gun was used, etc, etc. there’s a lot of different possible variables for doing damage formulas.

Bfcda3d8796b39076fd3eee75b35c587
0
Jedidia 101 Jul 18, 2005 at 07:42

@BlinkerGuy

Example:

Armor=100
Health=100

Rain gun damage=100

Result after the raingun damage:

Armor=33
Health=66

[snapback]18061[/snapback]

well, the formula looks pretty easy…?

Armor = PresentArmor - GunDamage * (2/3)

the value in the bracks could eg. stand for an ArmorClass, meaning that an Armor with class 1/2 would block half the damage instead of two thirds

Health = PresentHealth - (GunDamage - GunDamage * (2/3))

which would leave the unblocked rest of damage to health

I have no Idea about FPS, indeed I never even played it (don’t even know what the shortcut means :closedeyes: ) so I don’t know if the game works that way. This is just a possible way to get the results you stated, and it’s the Way I would do it.

B7257332ac4ff66d7a57708860c30904
0
cheng 101 Jul 18, 2005 at 16:31

@BlinkerGuy

When making an FPS game, there is something called armor which reduces the damage for the health.

Example:

Armor=100
Health=100

Rain gun damage=100

Result after the raingun damage:

Armor=33
Health=66

Anyone? I spent hours doing a google search for it but came out empty handed.

[snapback]18061[/snapback]

I’ll respond to this in a more general way, hoping that is what you’re looking for, rather than an application specific answer. This is a common problem that a lot of programmers face - you’ve gotten to the point where you have no problem putting pictures, models, levels on the screen, which always seemed to be the hard part, but is really only the foundation on which an actual game is built.

Most formulae you’ll need can be reduced to this form:

f(a) = mx+b

where a = the desired result; m = a scaling constant (possibly a complex one); x = a variable (possibly a random number); and b= an offset. You made need to change the equation to an equality, or a condition (programmatically, of course), such as

if (f(a) < THRESHHOLD_VALUE), etc., but the principle remains the same.

You might recognize this as the general equation of a line from your pre-calc class. It’s a pretty useful formula for a lot of more or less simple problems.

So how does this help you?

Well, if you have a design document, refer to it, and find all of the factors that are used to determine a hit, or damage, or whatever it is your working on.

Don’t have design document? No worries, it just takes a little longer, and you probably want to start one - even it only consists, at this point, of comments embedded in your code. Something like this: (just pulling stuff out of thin air here)

// Things that affect the amount of damage taken:
// 1. The state of current armor (as a percentage)
// 2. The angle of fire relative to headon (as an offset percentage)
// 3. Possible ammo modifier (to account for heat seeking missile and grenades)
// 4. The targets evasion skill
// ….
// you get the picture by now

Now, you need to decide (it is your game after all) how much of an effect you want each of these factors to have and how you want them to inter-relate. I generally start out simple, test, add complexity, test, add more complexity, test, etc. I put the formula into a spreadsheet or my graphing calculator and run it a few thousand times to make sure I’m getting the kind of numbers I want and tweak until I get what I want.

A couple of tips here are:

  1. Normalize your quantities. I like to use percentages, so I design from the ground up to express as many numbers as possible into this format.

  2. Avoid floating point calclations wherever possible. This may be just becaue I’m old, but I try to keep everything as integers, then format the numbers once to the screen when the appearance of floating point is needed. So, while I might present percentages to the user, I’m really using whole numbers between 1 and 100, and using integer arithmetic - usually just throwing away remainders to keep things neat.

  3. Multiply or Divide by 2 or multiples of 2 as often as possible - thus bonus and penalties tend to be 50%, 25%, 12.5%, 6.25%, etc (repeated division by 2). This is easier on the CPU because it is simply a right shift or a left shift operation.

So, to show a simple example, your formula might look like this

damage = AMMO_TYPE * ((Armor/2) + (angle mitigation) + luck_factor)) - distance_factor

Using the general formula I gave you above, you can see the correspondence:

m = ((Armor/2) + (angle mitigation) + luck_factor))
x = Ammo_type
b = distance_factor (we’re adding a negative number).

And my dad always said I would never use any of that math in real life.

Hope this helps.