|4.21| help me rotate my actor towards a surface | walk on walls |

reference to help understand what I mean: Unreal Engine 4 : Custom Gravity Plugin - YouTube

so I have a character who can walk on walls when I walk up to them. My problem is how I should find the correct forward vector to make the transition from the ground to the wall smooth. The up vector should be the normal of the wall, so that part is easy. Try to visualize, If you have a wall in a game and you want to walk up it. Maybe you look straight at the wall, then when you walk up it the wall becomes the ground and you are looking straight up in world space but you feel like you are looking the same way if that makes sense. Now, If you walk towards the wall sideways then the forward vector would be basically the same but the right vector will be up instead. Nod if you understand, if not, let me know.

when I say walk up walls I mean on any surface, 90 degrees walls just happens to cause me the most issues. I have tried a lot of stuff already and I’m kind of lost, any help would be appreciated.

I’m actually 99% sure there is a built-in function for this exact problem but I never remember what it’s called.

I haven’t tested any of this, so it could be off somewhat. But I think my thoughts are at least in the right ballpark.

The way I figure it, you first want to find a rotator that represents the rotation between the up vector for the starting reference frame (e.g. the ground) to the up vector for the destination reference frame (e.g. the wall). As you already stated, these up vectors are simply the normals of the surfaces, so, indeed, that part’s easy. So, to begin with, we’re looking for a rotator that represents the rotation between surface A’s normal and surface B’s normal.

You should be able to use the Make Rot from XZ node (or perhaps one of its sibling nodes, which can be found on the blueprint Rotator page) to plug in your surface normals, and receive a Rotator as the return result. You should then be able to use that Rotator to rotate the player’s forward vector (using the Rotate Vector node), and therefore point the player into the same direction relative to surface B as the player was pointing while attached to surface A.

To smoothly interpolate between the player’s forward vectors, you can try using something like the Ease node. (Or, if you’re comfortable with a linear interpolation, just use a regular ol’ Lerp node.)

Of course, at the same time as you’re updating the player’s rotation, you’ll have to be updating the world’s gravity vector (that is, changing the perceived “down” direction), plus updating a probable handful of other things to make the wall surface look and feel like it’s the new floor. I don’t doubt that getting this right will be tricky.

It might also be tricky to implement an intelligent, event-based system that detects when the player is attempting to change surfaces. (In other words, answering the question, “Is the player trying to walk on this wall? Or just walk near it?”) You don’t want the player’s orientation changing at the wrong moment, or by accident.

But, nevertheless, as the video you linked proved, it is possible. That means it can be figured out. And sometimes that’s half the issue right there.

Good luck!

thanks so much! I was not able to make a rotator like you said, I tried all the “make rot from so and so” variants. Perhaps I misunderstood you. I was, however, able to do something similar by rotating it around the cross product, using the dot product with acosd as the angle. Slight issue however, If I want to start walking on the roof. Then instead of facing forward but upside down, I end up facing backwards but upside down. So it’s like I’m doing half a backflip or frontflip rather than a sideways flip, not sure what those are called.

To be honest, this might be fine but I have this syndrome that makes everything have to be perfect before I can move on. You have already helped a lot but do you have any idea why this is happening, how to fix it?

btw, the gravity stuff. There is a free plugin for that, It’s really great, just bad at the rotation part. Directional gravity - Unreal Engine 5 - Tutorials & Resources by Tefel

I’m not at all sure why it’s orienting you backwards when stepping onto the ceiling. Maybe it’s due to the cross product being valid in two directions, with one causing the subsequent rotation to be reversed? (Something to do with a right-hand versus left-hand orientation thing?)

Also, I’m surprised you had issues with the “make rot from so and so” nodes, but I probably overlooked something.

To sum up, I really don’t know what’s going on, but I’ll try to do some testing.