I am making a top-down game, and right now my character rotates with the mouse cursor, but when i press any of the WASD Buttons i either go straight following the x axis, or sideways following the y axis, but i want my character to go forward, backward, and sideways relative to where my character is looking, and not where he/she is at. Could someone please help thanks.
You’ll want the yaw direction (ignore pitch & tilt) from your character to the cursor and turn that into Forward and Right vectors.
Multiply the Forward vector by your Move Forward input value.
Multiple the Right vector by your Move Right input value.
Add those two vectors together and pass the final vector it into the Add Movement Input node every tick, as opposed to using separate More Forward and Move Right input events.
I find there’s a few bugs with getting input values in the Character BP so I get the Move Forward and Move Right values in the Player Controller and pass them over to the Character BP where I do the maths and pass the final vector into the Add Movement Input node.
Thx’s for the reply but i’m still kind of new to unreal, and everything you are saying is pretty foreign to me. My question is how exactly would i go about doing what you told me to do?
I’m not sure if this will help elaborate on what Nigel.Monkey provided to you, but:
- If you follow the UE4 tutorials, you should notice that the Add Movement input function (in your character BP) when the target is self is what causes your character to “move.” The World Direction input for that function is what determines the direction that your character moves in. I believe the tutorials will have you use separate Move Forward and Move right inputs (which I don’t really have an issue with), which means that moving forward/backwards is a separate “Add Movement input” than moving right or left. I’ve never really had too many issues with the character blueprint, but the gist of any solution is this: Find a way to calculate the direction you want your character to move in, and plug it this into the World Direction of your Add Movement Input.
The way you find this direction can vary depending on what you want. For example, for my projects, I want my character to move where my camera is facing. So I take the camera component, get its relative rotation, which is made up of the X(Roll), Y (pitch) and Z(Yaw) and break it by using the Break Rotator Function. I only really need to mess with the Yaw so I pass the Z value to a “Make Rotator” function (with the other two values being 0) and these values are returned to Get Forward/Right vector before it’s passed to Add Movement input. World direction only accepts a vector (composed of the X, Y and Z), which is why you need pass the values to Get Forward/Right vector function before you plug it into the Add Movement Input.
Nigel.Monkey’s solution is a bit different but the idea is the same. You grab the yaw direction from your character/cursor (rotation), do some math with it, and pass it to Add Movement input. However, I’m not sure where your input values are coming from since your game is top-down…
Maybe take a look at these to get a better understanding of similar solutions and tweak it for your own:
Hope this helps!