Download

How to calculate player height from ground?

Hello Unreal Experts,

Can anyone help me understand how I might go about calculating the current height of a character from the ground? As the player jumps, I would like to have events trigger at certain points which are dependent upon how much further the player must fall to make contact with the ground.

Any ideas?

Thanks
SVR

You could raycast straight down and subtract the half capsule height.

It’d be really nice if the character origins could be placed at their feet, but you can’t change the root component on the default character… :\

From the characters components, capsule component>get capsule half height store this in a variable in your construction script.
In the event graph
event tick>
get actor location> break vector
subtract capsulehalfheight from the z component
make vector using the x y and new z
single line trace by channel, set channel to visibility
use the vector you just made for the start location
make a second vector by subtracting a z value that you want to trace down to
take the hit result >break vector
subtract the hit result z from your original z minus capsule halfheight
get the absolute value for the distance to the ground

If you’re using the default Character blueprint class with the Character Movement Component, the C++ code actually already does this already for part of it’s ‘FindFloor’ function. I’m not certain that it’s exposed to Blueprints, but the basic functionality is that you do a line trace from the characters world position to some distance underneath the character.

Get the Z-component of the line-traces hit location (drag off of the Single Line Trace node and create a ‘Break Hit’ node), subtract the Actors world-position Z-component and that will give you your altitude as a float value. I’d also recommend adding a check to make sure you actually hit something before returning the altitude, so you don’t start getting random things going off at large heights.

Awesome! I was able to figure it out after going back and spending some time in the documentation and tutorial videos. Just knowing where to look and how to best go about it saved me SO much time.

Thanks to both of you!

SVR

I had it open after you guys pointed me to it so I figured i’d share: