How to get the Z coord of the next collision object

Hello everyone!

I am trying to make my Character move along a spline in my 2.5D game. I achieved this behavior but not quite the way I imagined it at the beginning.

I want to put my spline above all the obstacles and terrain and stuff (and have it drawn in a 2D manner on the XY plane). I want the character to follow along the spline only on the X and Y coordinates, but I want it to stay on the ground.

So I think the right question would be: how to get the Z coordinate of the closest collision surface (like the End does in the Level Editor)?

EDIT

I am using the getLocationOnSpline macro to move the player to that calculated location, and the getRotationOnSpline which is implemented in the same manner

You could try a raycast or a sweep using the capsule geometry on the Z axis direction. It will return the closest hit location. But I suggest using physics for gameplay character movement. Then gravity would pull the character downwards and you wouldn’t have this problem.

You can’t do that. You would have to set the speed of movement for the character actor(capsule) on X and Y axes. And the Unreal integrated physics will compute the position on Z axis. Careful, though, because it will not be able to climb obstacles that are too high, anymore. Controlling the whole position of the character is bad practice, because you are not able to simulate collisions with other objects.

The other question I though of when I wrote this post was How can I control player location only on the XY plane (and let Unreal calculate the Z one based on simulation)?. See my update, please! How could I allow gravity do its job when I control the entire location vector?

Thanks! I found out that the Capsule Component’s location on Z can give the data I am looking for so I am now controlling only the XY axis on the spline, while the Z is controlled by simulation. Am I right?

If you tried it and it works as you intended, then you are right. But I didn’t really understand what data you are getting from the Capsule Component.