[GUIDE] Calculating fall damage from Hammer Units

Discussion in 'Tutorials & Resources' started by Narpas, Aug 23, 2019.

  1. Narpas

    aa Narpas Takes way to long to make and update maps

    Messages:
    428
    Positive Ratings:
    407
    Have you ever wondered how to calculate what damage a player will take from falling a certain height when designing your maps? Well, wonder no more!

    Base fall damage in TF2 is calculated using the formula (5V)/300, where V is the players velocity in Hammer Units per second. To calculate velocity, we can use the formula A√(2X/A), where A is the acceleration and X is the distance. Since gravity accelerates players in TF2 by 800 HU downwards per second, we can plug that in as 800√(X/400). Plugging that into our earlier formula, we get (4000√(X/400))/300, which we can then simplify to (2√X)/3, with X as the height in Hammer Units. However, we are not done yet, as this simply gives us the percentage of damage, so to get the exact damage to player health, we must first divide it by 100 and multiply it by player max heath, giving us the formula H(2√(X)/300, where H is player max health and X is the height in HU. However however, we are still not done, as damage deviates randomly by ±20%, so multiply this number by 0.8 to get the minimum damage, and 1.2 to get the maximum. Also keep in mind that fall damage doesn't kick in until the player is traveling over 650 units per second, which will be your speed if you've fallen over about 264 HU, meaning that the player needs to fall at least 265 HU to take fall damage.

    Now, you probably didn't read all of that, so here's all of the formulas you need:
    Code:
    Damage Percent: P=(2√X)/3 for X>264.0625
    Average Damage: D=H*(P/100), or D=H*(2√X)/300
    Max Damage: 1.2*D
    Min Damage: 0.8*D
    
    X = Height in Hammer Units
    H = Max player health
    Hope this helped, and happy mapping!
     
    • Thanks Thanks x 1
    • Like Like x 1
    Last edited: Aug 27, 2019
  2. Narpas

    aa Narpas Takes way to long to make and update maps

    Messages:
    428
    Positive Ratings:
    407
    Edited 2019/08/27: Simplified some of the math down and added in a note to say fall damage doesn't take effect until player velocity is greater than 650 HU/s
     
  3. [NGPU] Revetron

    [NGPU] Revetron L1: Registered

    Messages:
    7
    Positive Ratings:
    1
    If anyone is interested, here is a script that does this calculation. This is the source code:

    #include <stdio.h>
    #include <math.h>
    #define min_dist 264.0625

    int main() {
    double X, D, max_D, min_D;
    int H;
    printf("\nWhat is the fall-height in HU: ");
    scanf("%lf", &X);
    printf("\nWhat is the max player health: ");
    scanf("%i", &H);
    if (X>min_dist) {
    D = (H*(2*sqrt(X)))/300;
    max_D = 1.2*D;
    min_D = 0.8*D;
    printf("\nThe max damage is: %lf", max_D);
    printf("\nThe average damage is: %lf", D);
    printf("\nThe max damage is: %lf", min_D);
    } else {
    printf("\nThe fall is not high enough to cause injury!");
    }
    }
     

    Attached Files:

  4. Da Spud Lord

    aa Da Spud Lord Occasionally I make maps

    Messages:
    1,312
    Positive Ratings:
    866
    Inspired by Revetron, I decided to create my own fall damage calculator out of boredom. This one's in Java instead of C++ though. Enjoy, I guess.

    Also Revetron, you should probably put some sort of delay before your program exits, as if you launch the program by just double-clicking the .exe, after entering the values the program exits immediately without letting me see the results. Otherwise, it's nice.
     

    Attached Files:

  5. [NGPU] Revetron

    [NGPU] Revetron L1: Registered

    Messages:
    7
    Positive Ratings:
    1
    Hi Da Spud Lord,

    Thanks for uploading the same function in Java. Btw, when running my executable, I recommend running it through Command Prompt rather than clicking on the actual file. Also, it is written in C not C++.