Rotating a mesh in world space from the impact normal of a ray trace

Essentially what I’m trying to do is to rotate my mesh so that it is always 90 degrees from the impact normal, atleast in pitch and yaw, as the player still needs to be able to control facing etc.

At the moment I’ve managed to get it partially working, but only if the player is facing the right way on the slope. Attached are some screenshots that should get the idea across as well as my current BPscript.

Whichever way the character is facing, he needs to be correctly aligned to the slope.

Gave this a try, seems to be outputting mostly the same result, as in, not facing correctly downhill.
Is it worth having several ray traces in a cross pattern and working out the difference between the forwards most and the rear most to calc an angle ?

Rotate the impact normal around the axis x=0 y=0 z=1, then make rot from z.

1 Like

I realize this question is a few months old, but was a solution ever found? I’m trying to do a similar thing and getting the same results.

I got this to work for the ‘insect walk mode’ of my game.

I’ll try my best to summarize the code: I calculate the Delta Slope each tick by comparing the RotFromZ of the current ground impact normal to the previous value and also ‘Delta Yaw’ by comparing the current RotFromZ Yaw with my character mesh’s current Yaw. Using both data points I figure out if the character (in my case a butterfly/bee insect) is aligned along the slope (meaning pitch needs to change) or perpendicular to the slope (meaning roll needs to change). IIRC the ‘Delta Yaw’ is what you will use to determine not only whether the character should change pitch or roll but also whether the pitch should be in a positive or a negative direction (orientation).

Each quadrant of the Delta Yaw angle has a specific meaning for pitch influence, roll influence and positive direction v/s negative direction. So I check which quadrant the Yaw angle resides, for eg: among quadrants 0–90 v/s 90–180 v/s 180–270 v/s 270–360 v/s 90)–0 v/s -(90)–(-180) and so on. For best results you need to interpolate between the influence of pitch and roll depending on the character’s alignment, this is because your character will seldom align perfectly along the slope or perpendicular to the slope.

Unfortunately I don’t have a single screenshot I can share to illustrate my point as I did this in C++ and the code is deeply entwined with my upcoming game’s code; the solution can be built completely in blueprints if that’s what you’re after. If my high-level explanation was not clear I can try making a dev diary with actual implementation details (if I find the time though - no promises!)

Here’s a video of mine where you can seed the effect in action - [VIDEO OUTDATED] Intro to Drunk On Nectar (PC Game) #1 - Pollination - YouTube
(the effect is subtle, check between 0:30-0:40 seconds where it’s easier to see)

This solved my problem thank you.