Hello, thanks in advance for any help - I feel this shouldn’t be as complicated as I’m making it.
I’m trying to make a pawn walk on walls using FloatingPawnMovement. I line trace in front of the pawn, and grab the hit location and normal. But from here how do I calculate my new actor rotation given my current rotation and the surface normal?
For example, in this photo my initial rotation is (0,0,45) and the Normal of the wall in front of me is <-1,0,0>. I know my final rotation should be (90,45,90) as evident in the details panel, but what BP functions take me from that initial rotation + normal to the final rotation?
I tried to do some stuff with cross products as seen in the image below, but it only works if I walk into the wall front on. If I walk in at any glancing angle it does not seems to handle that.
Please help! This vector/rotator math is doing my head in and I can’t figure out if I should be using TransformRotation, Cross, MakeRotFromZX in some combination or something else. I essentially want to rotate my pawn’s reference frame until its up vector matches the normal I hit, but how?
Try either RotFromX, or RotFromZ ( on the normal pin ) 
Thanks for the reply! I tried using MakeRotFromZ on the normal, but then my pawn gets the wrong forward vector (it will just point due west regardless of the angle of approach, as it’s not using the pawn’s rotation at all in the math then). I’ve tried to use MakeRotFromZX (again passing the normal as the Z) but I can’t figure out how to calculate the X (forward?) vector part…
I’ve tried messing around with CombineRotators, ProjectVectorOntoPlane, etc but can’t seem to sort it out. It’s important for the pawn to maintain its proper forward orientation as I illustrated, otherwise if you walk forward over a change of plane (W key) and then back again (S key) you won’t end up where you started. I want to be moving in a line of sorts, not drawing spirographs 
It’s probably the X your pawn already has, no?
Well no, unless I am misunderstanding something. Initially my pawn has rotation R:0,P:0,Y:45, so his up vector is <0,0,1> and his forward vector is <0.707,0.707,0>. This is the unselected pawn in the first image.
The trace will return a wall normal of <-1,0,0>
The selected pawn in the image (state after rotation) should have up vector <-1,0,0> and forward vector <0,0.707,0.707>.
So really I suppose the question boils down to how do we go from initial forward vector <0.707,0.707,0> to final forward vector <0,0.707,0.707> given the surface normal of <-1,0,0>. But I need a general solution obviously, can’t just use a branch to rearrange the X/Y/Z coords 
Once you can do it with a jump, then you can do it with a rinterp.
Not quite following you - I’m not worried about the rotation being jerky (I can definitely solve that with lerp or rinterp) the problem is I can’t figure out the math to calculate the new forward vector for input into MakeRotFromZX (assuming thats the best way to do this…)
If find this leave my forward direction intact, but aligns it with the plane of the normal
( Ignore the location, of course ).
I tried that but it only seems to work if I hit the wall straight on. If you make a vertical wall and hit it at a 45 degree angle (like in my first photo) does that still work for you? For me its resulting in my pawn pointing due east, not up and right as desired
EDIT: just to elaborate, with that BP when approaching the wall from a 45degree angle the new actor rotation will be (P=0.000000 Y=90.000000 R=90.000000), so it is indeed losing part of my forward vector as the desired output should be (P=45.000000 Y=90.000000 R=90.000000)
Basically if I do that its preserving one component of my forward vector (the one shared with the normal plane), but the other component of my forward vector is being lost instead of being rotated into the new reference frame
Any angle I trace to wall at, will result in my ‘spider’ Z pointing out from the wall, and the forward vector being left untouched.
Of course it will align my spider flat with the wall, but won’t change it’s direction.
The white arrow shows where the trace will be. The red arrow shows my forward.
As you can see, when I make the trace, it works ok

First off, I really appreciate the help, thank you. But I don’t understand why it would work for you and not for me… has something changed in unreal 4 vs 5? (Im on 5) Here are two debug photos using the exact code you pasted. I’m tracing lines from just above my pawn to down and in front of it, and debug printing the result of MakeRotFromZX. You can see (R=0 P=0 Y=45) in the first photo as I approach as a 45 degree angle. As soon as the trace hits the vertical wall we can see that MakeRotFromZX now returns (R=90 P=0 Y=90) and our pawn is oriented ‘eastward’, not in the desired direction 
EDIT: One more photo showing what is roughly the desired behavior (obtained by using some ghetto code for visual aid purposes to manually set the correct orientation for this demo)
I’ll have to come back to you on this tomorrow…
Here’s attempt 2. I can orient the cube any way I want. Notice, any time I apply the alignment calculation ( cube flashes ), it aligns correctly, without messing up the forward vector.

Apart from more elaborate ( and yet still quite crap ) code to move the ‘spider’, the alignment code remains the same.
What is your blueprint component hierarchy?, I think that might have something to do with it.
1 Like
First off, thanks again for taking the time to help with this - your hero tag is well deserved 
So I stripped my code down to the absolute bare minimum and the issue is still happening. I don’t fully understand why your code appears to work but my similar code does not, however the code is so simple now that you can easily reproduce the issue I think and hopefully shed some light on it.
- Make a new Pawn BP, leave all settings default
- Add a static mesh actor and set the mesh to something with very obvious orientation (I did ‘Axis_Guide’ from the engine content), leave all other settings default
- Save BP and place a copy of this pawn in the world on the floor (so Z = 0), and set its Yaw to 45degrees. Place it such that it has a wall in front of it somewhere like in both of our demos.
- Add this code to the event graph:
Now run the game and watch the mesh hug the boundary of the wall/floor like in my earlier screenshot, vs maintaining its diagonal orientation…
I’ll check this later, but right now, I’d say the main difference is the setup of the trace.
I only had a direct down trace. Actor location to actor location - 250 ( say ).
Ok cool, I will play with my trace position for a bit, and look forward to any info you have later 
Still happens if I set the ‘projection distance’ multiplier in my code to 1.0
If I trace directly down without any added forward then the trace will never hit the vertical wall in front of me, so not sure this would be applicable for a use case with a moving pawn, vs just a spinning one as in your example