About Store Forum Documentation Contact



Post Reply 
Good Fall Damage function
Author Message
AndrewBGS Offline
Member

Post: #1
Good Fall Damage function
I was wondering if anyone would be willing to share a nice function for taking fall damage. I have something of my own, but I'm really not pleased with it, and it can sometimes get glitchy. So I'm hoping someone is willing to share some nicer way to handle this.
07-25-2013 03:21 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #2
RE: Good Fall Damage function
Given the physics engine should accelerate you during the fall you could use bands of damage based on velocity. Up to a certain velocity little to no damage on impact, over a certain velocity death on impact, in between the two make the damage vary from light to substantial proportionally.

This of course does not model the effects of what you are hitting (material/construction etc) on the impact. Taking that into effect would add more complexity. Not sure how realistic you are wanting this to be.
07-25-2013 07:07 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #3
RE: Good Fall Damage function
I know the basics, and I this is what I did so far, I have a boolen that check when my char is in air, to detect impact, and I deal damage based on the vertical velocity upon impact. The resulted damage itself doesn't really concern me, the important part is figuring that impact moment correctly. What I'm doing is sometimes failing and doesn't consider some rare scenarios. I was hoping someone could help me with a bit of code regarding that.
07-25-2013 08:25 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #4
RE: Good Fall Damage function
I would probably use collision as the impact determiner but apart from that what are the 'rare scenarios' you are referring to where presumably your system is failing you?
07-26-2013 07:39 AM
Find all posts by this user Quote this message in a reply
jagatai Offline
Member

Post: #5
RE: Good Fall Damage function
If i remember correctly in the Controller class there is;

Code:
Flt    timeInAir  ()C {return _time_in_air              ;} // get current amount of time while in air, as soon as player stands on ground this value is reset to zero

you could use that to determine time add that to distance and direction and then apply dmg based on your required criteria?

-J
07-26-2013 07:45 PM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #6
RE: Good Fall Damage function
That is pretty much what I am using. However, timeInAir alone doesn't work properly. Using it alone is somehow wrong;
I can't remember exactly, but I know the vertical velocity exactly when timeInAir was reset to 0 had a random value between the actual velocity and zero. (I don't know why, it just did; as if it dampened the char damn fast just before it reached the ground). To put it short, that didn't work well. I did some tricks based on that, but I have some glitches: there's still a tiny chance - if I fall on a slope for example - not to take damage. That's one of the glitches I remember, but there were a couple more.

What pixel Perfect said about collision....? Care to tell me more about it?
07-26-2013 08:19 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #7
RE: Good Fall Damage function
Right now I use ctrl.onGround() for checking if character is on air or not.

I also have separate variable to track length of total fall distance.
Because of damping, character will reach their terminal velocity too fast, also in case of mid-air slow down then faster, then calculate damage from this total distance upon ctrl.onGround() is true.

I'm planning to use collision, in case of falling into some unwalkable path that stop character mid-air but ctrl.onGround() remains false, what about using sudden change in velocity instead?
07-29-2013 06:38 AM
Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #8
RE: Good Fall Damage function
I did use that also (sudden change in velocity), but that is not reliable. I mean, it does determine the impact better, but it doesn't always get me the same result; Using velocity change, a 4 meter fall took me between 20 and 100% damage with the same function; I'll have to try again however, I think that was long long ago, and maybe not with onGround. I'll check tonight in more detail. Thanks for the idea.
07-29-2013 07:02 AM
Find all posts by this user Quote this message in a reply
Post Reply