Adjust Top Down WASD Movement Location By Camera Rotation

I have a top down camera and an 8 way movement input axis for WASD like so:

To sum this up, I am multiplying the input by 150 and adding that to the pawn’s current location to find the new location I want to move to. If I press W it will return the location with 150 units added in the x direction.

Recently I implemented the ability to rotate the camera around the pawn, but I need to adjust the location to account for this. For example, if I rotate the camera 180 degrees and then press W it should now return the location with 150 units subtracted in the x direction instead.

I’ve tried a couple different approaches, like using the rotate vector around axis node:

But this doesn’t work like I thought it might. I also tried adjusting the input axis based on the angle:


but I think there has to be a better way. Anyone have any ideas? Been trying to think of how to solve this problem for a while.

I approached this by adjusting the input based on the angle like I was trying in my first post:

If the camera angle is between -135 degrees AND 135 degrees OR between -45 degrees AND -135 degrees the input needs to apply to the opposite direction, with an accompanying function for the y input.

This also required a swap to determine which direction the input should apply to:

This works good enough, but I would still rather it work at any direction without having to define the ranges.

1 Like

Glad you found an adequate solution. I’m not sure if any of the concepts in this old post might help, but I did find a solution many years ago to adjusting movement based on camera direction (albeit for a ledge climb system). The function is shown in the last image of the first post: 3rd Person Ledge Climb Movement System (Shimmy) with Accurate Control Input

For the dot product comparison, if “Get Control Rotation” doesn’t work for your setup, you could also try “Get Player Camera Manager” and drag out and “Get Camera Rotation” instead (just make sure you have assigned a Player Controller blueprint in your Gamemode, and inside the Player Controller you have also assigned a Camera Manager blueprint).

I finally worked out an omnidirectional solution.

The missing key to understanding this for me was the realization that adding the direction the camera is facing (aka the forward vector) with the current character location will get a location in front of the character. This is illustrated below:

Getting the forward vector from a component takes into account the whole rotation, including pitch and roll, where I just want the forward direction based on the yaw/z rotation of the camera. You can split the struct pins instead of breaking them (aka BreakTransform), and then making new ones, to clean this up a bit too.

From there you just add or subtract your forward and right directions to get your desired end location, multiply it by a step factor (for how far away you want the character to move) and then add it to your current character location!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.