Align footprint decal to ground normal and foot direction

I’m struggling with the maths for this…

So, I want my 3P character to leave footprints behind her when she walks/runs. I have everything working fine when she walks on totally flat surfaces - the footprint decals spawn right under her feet and align themselves to her foot direction. What I cannot figure out is how to do this when the surface is anything other than flat.

I’m using a socket on the foot (each foot, actually) to line trace to the surface. This gets me the socket rotation when the impact occurs and the ground normal at the point of impact (which is a vector).

(1) If I spawn a decal with just the foot rotation’s rotation, the prints align to the foot direction on flat surfaces.

(2) If I spawn a decal with just the normal (converted to a rotation) as the decal’s rotation, the decals sit nicely on the irregular surface.

So how do I combine (1) and (2)?

I need to somehow combine a rotation (of the foot) with the normal (of the ground) so that the decals spawn in a way rotated to match the normal AND the rotation of the foot.

Any ideas gratefully received!


OK, I’ve solved it.

(1) Take the normal vector, negate it and get the rotation from XVector.
(2) Split the foot rotation and add 90 to the Yaw value (so that the decal casts downwards).
(3)Combine the above to make a new rotator, with the Pitch from the normal and the Yaw from the foot. Leave the Roll value as zero.

This seems to work great for angles up to 45 degrees, which is the limit my character can run on anyway. There’s some slight stretching of the decal on steeper surfaces, but nothing intolerable.