Download

Tracking jump height in real time

Hi,

I began working on a project about 6 months ago. Now I’m stuck at this, I need to track my jump height in real time to create some booleans for the state machine (I cast them from my Char BP). Anyone has a clue about how I could do that? I tried using ‘‘Get world location’’ but I can’t get it to center at my character without having him teleport to 0/0/0.

Thank you.

EDIT: Animation BP* not state machine, sorry

For characters with capsule component? In Character Tick, Do a line trace downward and check how far the line trace goes :

  1. Get the location of the character : Vector “location” = Character->GetActorLocation
    Now you know where the character centerpoint is is

  2. Get the character capsule half height : float halfheight = Character->GetCapsuleComponent->CapsuleHalfHeight
    Now you know how far from your location you need to go down to get to the lowest point of your character

  3. break location vector, make a new vector “lowestPoint”, keep the x and y coordinates from location Vector, and subtract halfheight from your location vector z vaue before plugging it in the z value of the “lowestPoint” vvector.
    Now you have the lowest point of your characters hit box. Now all we need to do is do a linetrace downwards from your lowestPoint vector

  4. LineTraceByChannel:
    Start: lowestPoint vector
    End : lowestPointVector but subtract, say, 10000 (for 100 meters) from the z value, trace channel Visibility.
    Now you have a LineTraceByChannel that every frame goes from the lowest point of the character down for 100 meters and checks if something is there.

  5. in your return value,you now have

  • a boolean “Return value”, which is true if something is less than 100 meters below you,
  • and an “out hit” struct, which,if the “Return value” boolean is true, you can split, so you can get the “out hit distance” float, which, if you are less than 100 meters in the air, gives you exactly how far above the ground you are

Note 1 : If you have performance problems or you know you always are less than 100 meters above ground (depends on level design), you can of course reduce the number in step 4.
Note 2 : Depending on how you make your game, you might want to consider creating a separate line trace channel in your project settings->collision that, instead of visibility, checks only for static world things (aka the ground). Tracing by visibility channel might give you wrong jump heights if something like a bird or a bullet or a leaf is exactly below you (and thus blocking the visibility trace).

EDIT: Oh yea, before you do all that, you can check with “character -> Is Falling” whether the character is in the air or not. You only have to do all that above if the character is in the air, no need to waste ressources when you are on the ground (in which case Is Falling is false).

I’ve had another answer from the Animation Forum. Thank you for the answer, it’s appreciated, probably still gonna use some of your design for other actions, thanks a lot!

Here’s the BP to track the Jump Height if someone else needs it.

JumpHeightTracker.png

If i read that correctly this will remember the last location z value when you were on the ground and calculates the difference between your jumping start z value and your current air position z value
However, when you jump from a cliff, aka the ground below you changes its z-value while you’re jumping, this will result in bad values.
If you jump off a high cliff, as soon as you go lower than your initial jumping position, until you hit the ground you’ll probably get negative “jump height” values.

Yes, when you get lower than your ''ZStart" location you go in the negative, it’s part of the feature I was looking for. When the character go under certain coordinates he enters a different falling animation.

EDIT: Your design tracks only the jump height and resets when you hit the ground?

Yes, it tracks how high you currently are above the ground regardless of changing ground heights. I thought that was meant when you said “tracking jump height”.
Ohwell, no harm done, now you have two solutions for two different problems regarding jumps. :wink: Have fun

@Pompompela i can’t see your image anymore. Care to repost it? I need this for my current project.

It’s been two years, it was just a paint sketch, pretty sure I deleted it after posting, sorry. :confused: