# Ive made a fall damage system however it has some bugs (ITS A LONG ONE)

**URL:** <https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [July 27, 2023, 11:54am UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626 "2023-07-27T11:54:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 27, 2023, 11:54am UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/1 "2023-07-27T11:54:38Z")

</div>

My fall damage system works by calculating the height using a line trace from the capsule component to the ground connected to the event tick. Storing it in the float variable “Character Height”

 ![Screenshot 2023-07-27 123832](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/e/f/bef0f0cdd1f0992cf7f6480b393d7e9fdcc95c96.png)

Then that value is used when the movement mode is changed to a falling state.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/d/6/ad6fc61b7aad8cfe2ee31c2108f28cbe0436e7e0.png)

And it starts calculating the damage through the function which is probably not the most efficient. And stores the damage in another float called “TmpDmg”.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/4/ce4b415ad6a3f317611669c977d7db27710b3359.png)

Then again connected to the event tick is the “Freefall” custom event which calculates is the z velocity is less than 0 and the character is falling connected to the branch which if true connects to a do once and another branch checking if the height is over 1500 and if its true, plays a falling animation montage. THEN on even landed it finally applies the damage stored in TmpDmg and then sets it to 0 again then resetting the do once.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/9/4491aecbd7f03ea7a748194859e7264274770327.jpeg)

**NOW THE PROBLEM**

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/c/65c23906851ed5ec82d88bc95c4ec08b002816b5.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/c/65c23906851ed5ec82d88bc95c4ec08b002816b5.mp4)
  
when the line trace detects the height before jumping, after the character jumps it applies the damage (i know how to fix this). HOWEVER when i jump off the platform there is no damage applied on landed since the death animation is played on death.

pls help thx 🙂

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [July 27, 2023, 12:15pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/2 "2023-07-27T12:15:47Z")

</div>

I didn’t look at this in much detail, but should this

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/c/d8c2dff9cdb70faa3c2a29e77ee1b9bb5429402d.png)

be this?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/6/83642269599e402198076e93d2795d127c0b133c.png)

---

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 27, 2023, 1:10pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/3 "2023-07-27T13:10:14Z")

</div>

what do you mean by the distance variable. Is it the character height? or height trace length

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [July 27, 2023, 1:18pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/4 "2023-07-27T13:18:22Z")

</div>

It’s the Z in this variable

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/7/337f446627a9d89d6f1ecf33f92df0b653a620d7.png)

If the capsule is leaning for some reason, just using a fixed Z won’t do the trick.

Also, you could do the damage like

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/f/a/1faf8265100ef7b1f77cad3df720e987439ea646.png)

Not exactly the same, but similar… 🙂

---

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 27, 2023, 1:41pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/5 "2023-07-27T13:41:41Z")

</div>

So Ive done both these things, am i supposed to plug the output of the function falling damage into the apply damage on event on landed because Ive done that and exactly the same thing happens.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [July 27, 2023, 1:51pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/6 "2023-07-27T13:51:33Z")

</div>

That’s because the order of events is wrong. You need to apply the damage, and THEN only play the montage is the player is dead.

Are you calling FreeFall on tick?

When you apply damage, should it get subtracted from player health?

Then when player health \< 0 → DoOnce → Play montage

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [July 27, 2023, 3:20pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/7 "2023-07-27T15:20:10Z")

</div>

To add a bit: IMO you should ditch the trace.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 27, 2023, 3:44pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/8 "2023-07-27T15:44:52Z")

</div>

Seconded. It seems overcomplicated atm and, knowing life, complexity will get out of hand sooner rather than later.

* * *

@Simolitical If it’s not too late, consider another approach:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/9/089e7f7ab0fec71220f6f4deca1a021de1f4d40f.png)

It takes walking off the edges into account, min height damage clamping and jump apex; it’s based on this curve:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/0/280b1d82e93f16b56eda6264f471a197eb2cf4c9.png)

Here the initial 200uus deals no damage but Landing from 610 uus would deal 75dmg. You’d need to add the montage or some other bits but the damage dealing works with this script alone and is quite flexible.

Good luck!

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [July 27, 2023, 4:31pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/9 "2023-07-27T16:31:15Z")

</div>

> [@Everynone](#):
>
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/9/089e7f7ab0fec71220f6f4deca1a021de1f4d40f.png)
> 
> image1675×933 245 KB

OnLaunched too!

![Apex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/2/98232a4e154f44c59b33965706d0157fb9c7bfc3.gif)

---

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 27, 2023, 5:46pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/10 "2023-07-27T17:46:28Z")

</div>

thanks a lot i cant believe it was that simple

---

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 27, 2023, 6:38pm UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/11 "2023-07-27T18:38:59Z")

</div>

If i want to add an anim montage of a falling animation from a specific height, i used this:

 ![Screenshot 2023-07-27 193645](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/d/dbde03a9ff17e96d1bf0bbd01cd5f521e0dbf9bc.png)  
however every time i jump it triggers the animation. I believe its because we are finding out the z coordinate from the origin 0 and not from the floor underneath. Could you help me find a solution.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 28, 2023, 6:45am UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/12 "2023-07-28T06:45:05Z")

</div>

You will need check the distance more often. You could use Tick or a Timer - 10x per second is probably plenty:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/1/611320553b3c1005859c721ddfad590223abfe28.png)

You could use a trace like before but a timer is somewhat easier to control:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/c/1ccc5db20be8e5b9c54bbfb04105ecba658d56e1.png)

This would trigger once we’ve fallen 500uus.

* * *

> If i want to add an anim montage of a falling animation from a specific height

Not sure if I understood this right, though. The animation triggers at specific height rather than once we’ve fallen a specific distance?

There’s yet another option to make it time based, have a look:

> [@How to tell (in seconds) how long Is Falling is activated?](https://forums.unrealengine.com/t/how-to-tell-in-seconds-how-long-is-falling-is-activated/241361/8):
>
> You could try it like this: Also, the Handle can do much more, for example: You could read data off it if you so prefer. You can also use this: [image] Or even add milliseconds together, like in the olden days wink

There’s a cool diagram at the top of this thread.

---

<div class="post-metadata">

**Author:** ![Simolitical](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simolitical/32/748963_2.png) [@Simolitical](https://forums.unrealengine.com/u/Simolitical)\
**Post date:** [July 28, 2023, 11:57am UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/13 "2023-07-28T11:57:58Z")

</div>

Thank you for everything, this is what ive come up with in the end.  
[fd posted by Simon.Oko | blueprintUE | PasteBin For Unreal Engine](https://blueprintue.com/blueprint/-p_nz3u7/)

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 27, 2023, 11:58am UTC](https://forums.unrealengine.com/t/ive-made-a-fall-damage-system-however-it-has-some-bugs-its-a-long-one/1241626/14 "2023-08-27T11:58:36Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
