Creating a Line Trace that runs parallel to the terrain

Hello!

I am implementing a dodge feature into my third-person action project by using a short line trace and interpolating the character location along it’s length (using SetActorLocation). Now, while this works fine by just drawing a single horizontal trace from the capsule component and having that be the track, the problem arises once the character dodges on the slightest slope; the line trace will move the character along a still horizontal direction, leaving him off the ground if dodging downhill or not going quite as far as they should if hoing uphill.

I would like to make it so that the end of the horizontal line trace is always the same height from the ground as the beginning of it (the collision capsule’s half-height, I believe) to make the trace always be parallel to the terrain.

The idea I came up with has me shooting a vertical line trace, starting from where the end of the horizontal trace will be and going straight towards the ground

and somehow using the hit distance or hit location of that vertical trace to modify the end of the horizontal trace so that it is always the same distance away from the ground, but I can´t figure out how to implement such a feature for the life of me.

Any of you math-savvy fellas could lend me a hand? I’d greatly appreciate it.

Thanks tons.

My BP code attached here:

First LineTrace is the vertical one, second is the horizontal, they’re one right after the other, the actual movement logic is offscreen but I wouldn’t believe its relevant.

bumping? maybe

buuuuuuuump

Okay, I’ve figured it out. I stopped using a line trace for the movement and rather I use a timeline that outputs a value that changes the actual character speed for the duration. Works like a charm and gravity keeps you on the ground without any fancy math. Thank yall for not responding I guess? lmao

Well… Three years later ^^… I’m on the same problem today on my side !
Sorry that I can’t solve your problem, but as I’m here and the topic is still unresolved, I bump it.

I’m pretty sure it can be done easily to trace a vector that adapt its trace accordingly with the terrain elevation.
But unfortunately i’m not a big expert on coding.

So if someone’s passing by on the topic, I would be very grateful for any little tricks.
I post my setup equally and a beautifull sketch to illustrate the problem :grinning:
(I think it’s exactly the same problem as the author’s)

I post