Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Fall Damage

Author
Message
JJJ0han
16
Years of Service
User Offline
Joined: 4th Oct 2007
Location: Brisbane, Australia
Posted: 2nd Nov 2007 14:40
Ok, now, while I'm working on my nice little FPS, I've been trying to slowly assemble the health system. The health is easy. Just a variable. But taking the health is a little harder. Now I'm not up to the player taking damage from bullets yet, but I'm up to the bit where I want the player to take damage from insane falls.

I've been experimenting for a while now but I can't seem to find a way to accurately allow the player to take damage.

Here's the code I have:



Now let me add a few points.

-I use Sparky's Collision DLL.

-My level is a matrix with quite a few steep hills.

-I've tried various things to replace the first line with.
if jumpduration#>0.01 and y#=0
if jumpduration#>0.01 and collide=1 (checks in a sphere radius for collision, function declared elsewhere in the script)
if jumpduration#>0.01 and SC_rayCast(0,X#,Y#,Z#,X#,Y#-10,Z#,2)=1
if jumpduration#>0.01 and SC_rayCast(0,X#+5,Y#,Z#+5,X#-5,Y#-10,Z#-5,2)=1

-I did search, but the only good result with an answer was for Newton which I had no use of.
Profit
18
Years of Service
User Offline
Joined: 19th Feb 2006
Location: United States
Posted: 2nd Nov 2007 17:52
Why not just check if 'vy#' is over a certain value?

common people are walking in line.

Mitsu Fly Ride.
Doc
16
Years of Service
User Offline
Joined: 6th Nov 2007
Location:
Posted: 10th Nov 2007 19:58
Here's how I do it, and it works quite well:

It requires a small gravity value that will work as an acceleration, which is more realistic anyway. Then you will have a variable containing the y velocity, and all you have to do is check when the y velocity decreases. You can set the maximum allowed fall value, like if it's only 5, the player hasn't fallen that much and won't take damage, after that you can start assigning damage.

This works really well, because if you just base it on distance then things that slow players falls will still kill them. Using the way I have described will make it realistic, based on how hard the player hits the floor, not how far they have fallen.

The right man in the wrong place can make all the difference in the world. -- GMan
Doc
16
Years of Service
User Offline
Joined: 6th Nov 2007
Location:
Posted: 12th Nov 2007 00:46 Edited at: 12th Nov 2007 05:39
I wrote a little demo however I tried to cut corners and just check the difference between the location it moves to versus where it is based on the collision. I posted the code but I realized that this wont always work so I took it down.

I will write a proper example asap.
My apologies.

The right man in the wrong place can make all the difference in the world. -- GMan
JJJ0han
16
Years of Service
User Offline
Joined: 4th Oct 2007
Location: Brisbane, Australia
Posted: 13th Nov 2007 11:29
It's fine. I've got plenty of time.

I've got the fall damage working, it just doesn't work on steep.. or actually.. non-flat surfaces at all though .

Though I'm mainly concerned how I'm getting my AI units some collision at the moment .
Doc
16
Years of Service
User Offline
Joined: 6th Nov 2007
Location:
Posted: 16th Nov 2007 17:14 Edited at: 16th Nov 2007 17:38
Ok, I think I got it working now
It's actually a very simple process, The hard part was making an "allowed Damage" so the player isn't super sensitive. The reason this was difficult is because sometimes only half the damage is received in the first loop and the rest the second time the program loops.
I made a little picture to illustrate this



Hope that clears it up.
So all the damage will be assigned just as it should, but the problem was that notice how 3 damage was dealt the first time, and 2 the second time.
Well what if you want the maximum allowed damage to be 4.
The player should recieve a total of 5 damage from this fall
However the first loop only deals 3 damage which is lower than 4 so no hp loss, and same for the second loop.

So the trick was to make it add up the damage from 2 collision checks and then see if it is enough damage to assign. I hope that works out all the bugs, please let me know if it doesn't.



lots of comments.
The total damage done in that example is 9, so if allowedDamage is 9 or greater no damage is dealt.

It should be easy to apply this to a 3D application, and will work with sloped surfaces, just make sure gravity is negative.

NOTE: you can always do further calculations for the damage. Like you could try doing "health = health - damage + allowedDamage" to make a smaller value or try multiplying damage by 2 or whatever.
I havn't experimented with this in an actual game so I don't know what calculation works the best.

The right man in the wrong place can make all the difference in the world. -- GMan

Login to post a reply

Server time is: 2024-09-27 08:28:55
Your offset time is: 2024-09-27 08:28:55