Rotate character left/right with A/D keys

I’m looking to simply rotate my character/camera boom (3rd person character) either left or right when the A/D keys are pressed. Everything I’ve tried ends up rotating my camera around the character mesh itself and not the character.

It sounds like you want the camera to stay fixed behind the character as he rotates with A/D, is that correct? (Also known as tank controls.) That will be easy to do. (But if that’s not what you wanted, let me know and I’ll try to find something else for you. :slight_smile: (Not sure what I’ll do, but I’m sure I can find a way.))

In your character blueprint, go to the components panel and click on “ThirdPersonCharacter(self)”. Now in the details panel, navigate to the “pawn” tab and check “Use Controller Rotation Yaw”. This will rotate the player so that he’s always facing the same direction the camera faces. This is essentially how you could set up a “strafe mode”. (You can even set this on and off with blueprint functions if you want.)

Now you just need to set the A/D keys to control this rotation.
By default, the third person template uses “InputAxis TurnRate” to add controller yaw input. Either change what buttons are assigned to that, or replace this with a different control mapping.

To configure the controls for your game, go to the “Project Settings” (found under “edit” on the Unreal window header) then click on “Input” under “Engine”.

I hope this helps.

1 Like

Hey thanks for the response! This might be what I want? What would the node be called to toggle this on and off from a blueprint?

Sure thing! But let me know if this is what you had in mind.

If you type “set” in the node search, you’ll have access to all the variables that the Character Movement Component has to offer. (You might have to disable “Context Sensitive”.) The node I was talking about earlier is “Set Use Controller Rotation Yaw”. I’m not saying that you’ll have to do this, I just wanted to make sure you’re aware of it in case you do.

Speaking of which, I see you’re a brand new member here. I’m not sure how much previous experience you have with game development, but either way it’s good to have you! ;p

Now, I’m still learning how to program this stuff myself. I was doing some experiments with rotation just a second ago. So I’ll go ahead and show you some blueprints I came up with that you can try if you want. :slight_smile: Just make sure you disable “Use Controller Rotation Yaw”! Again, I guess I’m not 100% sure what you wanted for your game, this is all just me playing around, but hopefully you’ll get an idea as to what you need to do.

This first one will smoothly rotate the actor in place as you hold down a specific key. Take a look and then I’ll explain how it works:

I created some booleans that tell us whether the player is holding down the A and/or D keys. If that’s true, we set the actor’s rotation to whatever it currently is plus a little offset on Z(Yaw). +10 for D and -10 for A. You can change these numbers to control the rotation speed. You could also use this method to control the camera if you want. That would look like this:

Below is a code that instantly centers the camera behind the players back, a common function in third person games.

Now take a look at this last one:

The “FInterp To” node is very useful! It allows you to “smoothly travel” from one float value to another. The “Interp Speed” controls how fast the transition happens. Just keep in mind that you MUST use some kind of tick event to keep the FInterp going. If you try to use a “single fire” event, you’ll likely notice just a little nudge or something. Edit: Oops! I’m sorry, the FInterp is for floats, but you should use an RInterp for rotators. Otherwise the actor may rotate around in the wrong direction.

I hope this isn’t too much information. ^^;

I have not heard from you in a while. How’s everything going?

Hey I stubbled on this looking for same thing but the code didnt work im probably missing something but idk what? still moves right and left direction.

@BananaBac0n this was very helpful. Thank you. I have just started UE4 in the last 24 hrs and the sphere in the tutorial I was using just wasn’t cutting it. I wanted a real model with orientation, but quickly realized I needed something more than just unlocking the Z rotation. Thank you for this, I can now turn and steer my character as I would in most 3rd person games I play.