2019-03-15 15:45:14

Doesn't have to be completely realistic.
Warning! Complex math may insue!
Anyway, if the default, and maximum health is 1000, what would be a good dammage formula for falling?
It will also depend on the surface you fall on of course, but for a base equation:
any ideas?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 16:27:26

Hi, i don't know if it is fine, but i would say:
current hight minus the coords the player gets to fall on. like let's say i am on a platform wich is 20 meters high, and i fall to 0, the final health that should be subtracted will then be 20. when you have 1000 health, you would then have 980 health.

best regards
never give up on what ever you are doing.

2019-03-15 16:35:21

hmm, interesting, but I want more realism. If you fall 20 feet, then your going to get a lot more hurt then that.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 16:48:27

simple:
if(heightz-playerz<10):
health-=(heightsz-playerz)
else:
  player:die()

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-03-15 17:18:05

@4, I don't understand that, what language is that? Py py?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 17:36:17

I think I've got it, I'll just have to iron out how to calculate the fallingspeed into the equation.
Base Health lost from falling: fallingdistance+fallingspeed*10 = fallingdammage

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 18:35:47

Are we talking realtime? If so, just go with v.y on impact.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2019-03-15 19:09:43

your algorithm should have a minimum threshhold  for falling height , since if the player falls down 10 cm then they shouldnt take 1 hp damage. so let's say that starts at 2 meters. from physics we have the potential energy of a object suspended in air is
= mass times gravity times height
mass and gravity are constants in this instance, so the variable  we are concerned is height.
from this equation, the energy of the impact is linearly proportional to height, so it is reasonable to assume the fall damage would scale linearly. so we can just multiply by the height fallen by a constant damage factor.
btw, the height fallen can be derived from the velocity  at impact, since
mass times velocity^2 = mass times acceleration times height
so, rearranging:
height = (velocity^2) / acceleration
at least that should be right... been a while since I done physics in high school.

so the basic algorithm would be in pseudo code:
int damage(height) {
if height > minimumDamageThreshhold
return height * damage_factor
else
return 0
}

for some extra realism, the minimum damage threshhold and damage factor can depend on the material of the surface the player fell on, so grass or water would be have greater threshhold and smaller dmg factor and for concrete or a bed of nails it would b the other way around.

2019-03-15 19:31:09

@8, omfg omfg oomfg omfg omfg!
I'm not even in high school yett! I like complex math but god daaaamn!

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-15 19:58:43

well use the curront ones until you learn those things then

2019-03-15 20:26:07

Oh, good thinking DragonLee. I would use more complex physics equation but I didn't think about the simplest way

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-03-15 20:56:21 (edited by Origine 2019-03-15 20:58:44)

Post 8 is correct, but it's easier to just calculate damage from velocity, because it's usually an info you have available:

damage = damage factor * velocity ^ 2

where velocity is the speed at which your character is going down. The sign doesn't matter here because of the square

So unless there are different gravities into the game, you don't need to divide by the acceleration, because the damage factor can just absorb it by being 9.8 times larger. Whenever you want to model something in a game, what's important is to know how it scales, then you can fine tune factors. In your case, you can choose different factors for different surfaces like post 8 said.

I don't know if you have basic physics notion, so here is a summary:

When we fall, we accelerate. On earth, the acceleration is -9.8 m/s^2, depends on where you are on Earth, there are some variations, but let's say it's -10 m/s^2. It's negative because by convention when it's going down it's negative and going up is positive. Since Earth's acceleration is towards earth, so dowon that is, it's negative by convention.

The unit m/s^2 can be read "meters per seconds squared", but don't be confused by that unit. You know velocity is "meters per second" or m/s, then acceleration is "meters per second, per second" or (m/s)/s or m/s^2. Basically, if I accelerate at a rate of 10 m/s^2, it means my velocity will increase by 10 m/s every second.

So say I'm in the air and my velocity is -5 m/s. Here minus means it's going down, I'm falling at this very instant at 5 m/s. But my velocity increases as I'm accelerating. After 0.5 seconds, my velocity is now -10 m/s. After another 0.5 seconds, so 1 second from start, it's at -15 m/s and so on.

In a game, we usually update parameters by ticks. So if you have a game tick every 0.03 seconds, then you would update your verlocity like that, assuming you are falling:
velocity = velocity - 10 * 0.03 = velocity * 0.3

You can update position like that:
position = position + velocity * 0.03
where 0.03 is tick length

When you hit the ground, calculate damage like that:
damage = damage factor * velocity^2

Of course you can add a treshold like post 8 said.

When you jump, just set velocity to some positive value. Say if you sset velocity = 10, then your character will start going up, as velocity is positive and will loose speed as acceleration is negative. After 1 seconds, velocity will be 0, meaning your character doesn't go up nor does it go down and then he will start going down.

Hope that was somewhat clear. But wait! There is more! You can calculate damage even more realisticly. This is because post 8 assumed damage like that:

1) As you fall, you rack up energy. The faster you go down, the more energy you rack.
2) On impact, the ground violently decelerates you, converting that energy into damage for you.

While that is true, it's oversimplifying. You see, base jumpers who can jump from really high without dieing roll and they hit the ground. This is to spread the impact on as much time as possible. It's also to convert some velocity into rotation. This is because what matters is not energy, but power. Power is energy rate so to speak, energy per second. You wouldn't die if you fell from 200m if you had a equally distributed impact over 1 month. What makes the impact kill is that it's really quick, less than a second.

But you cannot roll if you fall straight, so it depends on the angle at which you hit the ground. Angle will change over time of fall, because usually horizontal velocity is constant and vertical velocity is accelerated downwards.

There is also material bounciness, when you fall with high velocity, depending on the impact distribution, the ground material and the character shape and mass, the character will bounce. In real life, some people survived really high fall, until the second impact, meaning when you bounce, the second impact also inflicts you damage.

It also depends on which body parts hit the ground, if you fall on the head... good luck.

There is also air resistance. If you wonder if a free falling object will keep accelerating as it falls infinitely, well no, it doesn't. The fastest you fall, the more air tries to prevent you from accelerating, until you reach a point where air decelerates you so much that it completely evens out Earth's gravity, meaning you have a net acceleration of 0 m/s^2. This speed at which this happens is called terminal speed or terminal velocity and it depends on the shape of an object, it's orientation, mass, etc. This is why a sheet of paper falss slower than a glass, the sheet of paper's terminal speed is very low.

Remember when I said someone falling straight couldn't roll, well if they place their feet off-centered compared to their center of gravity relative to the ground, they can have a lever effect and create a tork converting some of the downwards velocity into rotation. So I simplified there.

What I want to get at is unless you are making a physics simulator, usually in games, we don't aim for realistic, but rather realistic "enough". This is also true for AAA titles. We approximate because it would take too much CPU to do the most exact calculations factoring in all physics concepts. But mostly because what's important in a game is fun. If you'd like your character to roll when he falls and is moving horizontally to reduce damage, just create a rolling sound asset and include that rolling damage reduction in your damage formula. If you want your character to bounce, add materials a bouncing index that will restitute some upward velocity on impact with a decay and a treshold. If you want your character to have a parachute to use air resistance to reduce damage, just set a max velocity with that parachute, say -10 m/s or whatever you like. If you want to put a mechanic that breaks physics, it's ok too, like those games where you can double jump, although it's impossible to jump on air for us humans, it's still a good mechanic.

So yeah, you can totally use damage = damage factor * velocity^2. Is it realistic, well not really. Is it realistic enough? Depends on your game, but mostly yes.

Note: the formulas here are based on Newton equations, but they were proven not exact, especially at high speeds by Einstein. So even using those formulas are simplification, because the difference is so small at low speeds that it doesn't matter.

Reading is one form of escape. Running for your life is another. ― Lemony Snicket

2019-03-16 00:15:43

if (this.onGround == false) this.v.y -= 9.8 * dt;
else if (this.v.y < -9.8*dt)
{ // This is when you hit the ground after falling.
falldamage = this.v.y * fallfactor;
// landsounds, etc
this.v.y = 0; // assuming you don't want to bounce.
}

I tend to like values between 5 and 7 for v.y when jumping, but the important thing to remember is that whatever v.y is at the start of a jump, it will be negative that when landing. So you should avoid falldamage for any value of v.y greater than minus jumpspeed, at least.

And dt is how much time each frame covers. If you're using timers, this will be time.elapsed * 0.001. If you're using fixed frame lengths, it's whatever that is.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2019-03-16 00:18:57

ah! my! brain! oww! ow! ow ow!

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-16 02:04:36

The more realistic you get the more complicated things become. That said, here's my take:
when any object falls down to earth, there are two forces (simplified) working on it:
1. Earths gravity, causing an acceleration (speedup) of 9.8 meters per second.
So if we would only have gravity, we'd end up falling faster and faster and faster with the same acceleration, 9.8 meters per second.
2. The air resistance, and here it gets interesting.
The air resistance is squared compared to the velocity. If you don't understand, it basically means that for small velocities the air resistance is allmost not present, but the larger the velocity, the larger the air resistance becomes, eventually balancing out gravity and making someone go down with a constant velocity (terminal velocity). Notice that when someone has a constant velocity the acceleration is 0 (Do you understand why?)
According to my google efforts, the max speed for a human falling down is 53 meters per second. This will yield the following:
v -= 9.8*dt; // gravity, we are falling down so negative
v += 0.003488786045 * v * v * dt; // air resistance for human

And here dt is the time elapsed since last computation. So let's say you check movement every 5 ms it will be 0.005. You can use the elapsed value from a timer.
So now you only have the impact velocity when something hits the ground. How you map it to health is dependent on your game.

Roel
golfing in the kitchen

2019-03-16 02:33:51 (edited by Mitch 2019-03-16 02:37:13)

From the physics that I remember (I'm still taking physics in high school, so this may not be correct) you also need to keep in mind your falling momentum and the amount of force the impact with the surface will absorb. For example, you would conceivably take more damage falling onto concrete rather than falling into water, due to the fact that more dense objects are not affected as much by forces, which transers it back to you. The reaction force of the ground acting on you (I think) tends to bleed off some of the momentum that you have achieved during freefall, and the firmness of the ground also plays a part. I haven't checked my facts completely, so take it with a grain of salt, but that's what I remember. 
Physics is fun!

A winner is you!
—Urban Champion

2019-03-16 11:09:05

16, that is right.

2019-03-16 11:19:07

hi
I think, eg if tile is 10, player should loos 1000 health: in each hight, 4 health should be lost: for first 3 hights(if hight is <3) or <5, player shouldn't loos any health
why I sed in each hight 10 health should be loos? we have mountain with hight of 100: in real life, if you fall you'll die? so it should be in game to make it realistic

2019-03-16 13:17:45

I think you should also make it that, depending on how the player fell off, he might fall on his side, face, back, head, causing different types of injuries and just different damages and possibly paralysis. Mind you, I couldn't do math for my life, so I'm useless there.

2019-03-16 13:53:52

Yes. What I wrote is only speed upon impact. Obviously different surfices do more or less damage. The easiest way to define this is to have a factor for each surfice which is multiplied with the health lost. For concrete this could be 1 for example, and water 0.1 (rough estimates). If you want to have more controll over the player's air resistance for example if you have a parachute, you can use the following formula:
v += 9.8/(tv*tv) * dt
tv is the target speed, for a parachute this might be 2 meters per second
But generally, the more realism the more work.

Roel
golfing in the kitchen

2019-03-16 22:14:11

Guys, gravity isn't 9.8 meters per second, it's 9.8 meters per second per second.
Second, after reaching a certain speed, landing on water is like landing on concrete since liquids do not compress. That's why form is so important when doing those 80 foot dives, they need to pierce the surface tension of the water.

Here's a wikipedia article on falling object formula.

https://en.wikipedia.org/wiki/Equations … lling_body

thanks,
Michael

2019-03-17 14:09:12

@21
You're completely right, it's been too long.. Still the formulas should be correct.
ANd especially with games, how would you implement getting to the correct form before landing? I have made the assumption (perhaps I should have stated it) that this would be a game similar to 2d platformer in it's mechanics and falling. Then, having predictable damage results but still them being somewhat realistic is what I'd aim for. If we start obsessing over realism the game itself can be advursly affected, we couldn't have creaking doors for example.

Roel
golfing in the kitchen