• News

• Industries

• Learning & Support

• Community

• Marketplace

# Pawn Z location according to ground surface location

Hi all,

I seek help and peace of mind! I have been fighting this issue for the past 3 days but I can’t find a solution.
So, what I have right now is a flying pawn that is set to always hover 150 units from the ground surface. Using a trace from the pawn location towards the ground, I always make sure that the pawn is at 150 units from the ground.
This work fine especially when climbing a hill but as soon as the pawn goes down that hill, the result I have (the visual behaviour of the pawn) is not what i want.
Going up the hill, the pawn adjusting itself to the ground surface should be instantanious while going back down it should actually take time to reach back the 150 units from the ground as if it was gliding.

Thanks for your help!

Look at these:

https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYeJX3xX44yzOb7_kTS7FPM/5kltaGld6fQ/

To add on to Nawrot, you’ll have to detect whether you are going up or down. If you’re going down, use the TInterpTo the location you’re trying to go, and going up you leave the function as you have it. You can see if the actor is going up or down by checking if the raytrace is shorter or longer than 150 units.

One more more tip:
Calculate DOT product between vehicle FORWARD vector and NORMAL vector of ground below from linetrace. (Remember to normalize vectors before feeding them to dot product).
Just look at values when you go up and when you go down, i think flat surface will be 0.5 , going down 0 to 0.5, going up 0.5 to (but i am not quite sure about those numbers, so experiment yourself).
You also can do two linetraces, one before center of vehicle and one behind, and get direction of slope from it.
When you have boolean value telling that vehicle goes up or down, simply feed different interpto speeds to interpto node. Slow for going down fast for going up.

Thanks both of you,

I started implementing quickly some new logic last night using bits of the hover simulation and the results are quite interesting…
So far adding Force to the pawn to keep it 150 units from the ground works; and when the Trace doesn’t detect any ground (more than 150 units away) the pawn goes back smoothly to 150.
I added the Linear damping and the Angular damping but if I keep the Angular, the pawn’s rotation is not affected by the normal of the ground ==> the pawn stays flat and will eventually collide with the slope.
Losing the Angular and replacing it by a “Make Rot from ZX” and “Set actor Rotation”, the pawn will follow the normal of the ground and be able to climb that slope… but I lose the Roll of the pawn making it harder to turn.

Now, when gliding (Trace doesn’t detect ground), the Roll is back and moving around feels good. (since it’s set to do nothing when not colliding, it’s using the “normal” logic to turn)

I will work on it again this weekend and will post the results.

Thanks again!