How to properly align control orientation to screen axis?

Hi,

I keep running into a brick wall with this one. I need help orienting my control rotation (preferably only yaw) so that it aligns the player’s movement to the vertical axis of the viewport, no matter the orientation of the camera.


In this example, I’ve moved the character to the left of the viewport, and as you can see the control rotation aligns with the grid on the ground. The further away from the center of the screen, the more angular the toward/away movement.

To make toward/away movement feel good, I would rather the axis rotated to look like this (so that the green Y axis lines up with the 2D vertical/Y axis of the viewport.

I’ve tried using a Find Look At Rotation node to get the yaw from camera to character, but it applies too much additional rotation and feels worse the more elevated the camera gets. I’ll simply be using the right vector of the camera for horizontal movement, so that’s not a problem.

Any help with this would be greatly appreciated!

Thanks.

First, get ahold of the Pawn being controlled, and the Camera doing the looking.

Then, calculate the vector that’s Pawn.ActorLocation - Camera.ActorLocation (slightly different if you’re in blueprint vs C++, but should be straightforward.)

Then, set the Z component of the value to 0, and normalize. You now have a “forward” vector. You can use the unit Z vector as up, and cross product the two together to get your right vector for the full basis. (X = forward, Y = right, Z = up, Unreal left handed coordinates.)

Or use “make rotation from xz” to do the same thing.

Something like this will do it in blueprint (this is from a player controller):

Note that the multiply is element-wise (“set Z to zero”) not cross product. The cross product happens automatically inside the make rotator node.

2 Likes

Here is an example where you first calculate an OrientationPoint (the point where the projected lines of the frustum on the ground intersect) and use this for MovementDirection
(similar to this thread How to measure frustum at a given distance from camera? - #2 by Megadoom2oR) and Rotation (the rotation method @jwatte described):
RunTowardsCamera.zip (839.4 KB)
Maybe there is an easier way, did not need something like that before :slight_smile:

1 Like

@jwatte @L1z4rD89 Thanks to you both! I will try this later and report back!

1 Like

Thanks @L1z4rD89, you pointed me in the right direction, no pun intended.

I will move this to the player controller eventually, but here’s the set up.



1 Like