How can I get the angle of the ground on which the character stands?
Want to get the ground angle and associate it with character’s animation.
Please ask for help.
You can make line trace and get normal vector of the ground, with SingleLineTrace and MultiLineTrace functions. Angle is a 2D value, so maybe you need to project this ground vector on some plane and calculate angle. Or maybe it is better to use 3D vector itself.
I’m assuming you’re using blueprints here, but if not then the following info applies to C++ too, just implement the same methods.
So, to get the angle of the surface you’re stood on you want to perform a ray trace directly down from the character (i.e. down vector). The trace should hit the floor and from that, you’ll be provided with some ‘hit’ data.
Some more information about Line Trace here: Using a Single Line Trace (Raycast) by Object | Unreal Engine Documentation
Depending on what the surface is, you might just be able to get the hit actor and look at its rotation. This works well in some cases (i.e. when you have a flat actor which has been rotated to an angle), but not so well when you are using terrain which is a single actor where the polys describe many angles.
If you need to do the more complex case, then the ‘hit’ data contains the Impact Normal of the surface hit.
And a good explanation of what a normal is here: Normal (geometry) - Wikipedia If you’re still not sure put a flat object on your desk and then stand a pen on it. The pen is pointing straight up, and that’s your normal. If you lift one edge of the object then the pen will start to tilt, the direction it’s now pointing in is the normal of the object when it is tilted at that angle.
So, now you have your impact normal, and you know constant vectors like up, and left you can use that to find the angle of the surface.
This example here does this: Setting Pawn Rotation to Match the Floor - Blueprint Visual Scripting - Unreal Engine Forums or more specifically this: http://i.imgur.com/uUwOOI4.jpg
awesome thanks for this!