Announcement

Collapse
No announcement yet.

How to calculate player height from ground?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    Originally posted by SVR33 View Post
    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.... :\

    Comment


      #3
      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

      Comment


        #4
        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.

        Comment


          #5
          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

          Comment


            #6
            I had it open after you guys pointed me to it so I figured i'd share:
            Click image for larger version

Name:	45f2f18fbc92ff0601a95e5040049f60.png
Views:	2693
Size:	60.4 KB
ID:	1617851

            Comment

            Working...
            X