Rotate and zoom camera in top down template?

Hi all, I’m using the Top-Down template and I’d like to be able to manually rotate the camera around the player independently of the players movement using the A and D keys, and the W and S keys to zoom in and out.
I’d basically like to do exactly what this video is showing: - YouTube
I’ve been Googling for ages and tried various blueprints but nothing I’ve tried so far works.

I’m new to the Unreal Engine so if you could be very specific with what I need to do then it’d be much appreciated.
Thanks a lot!

1 Like

Hello @Andy Green,

I think I have a solution for you.

First you want to create two new axis mappings in the Input Manager under your Project Settings. They should loo like the picture below.

51856-characterrotation.png

Next you want to add the following code to the Event Graph in your TopDownController class. You add it there because that class is set up to receive input. I will paste and explain the code below.

Camera Rotation:

This essentially gets the player pawn and uses a cast node to check whether the player controlled pawn is of the “TopDownCharacter” class. If the pawn is of the “TopDownCharacter” class then it proceeds to change the relative rotation of the spring arm component on the player controlled pawn. The spring arm is essentially the component that holds the camera in the air above your character. I calculate the rotation by combining the previous rotation with a new rotation which only has a Yaw value. This Yaw value is either incremented or decremented based on the Axis Value of the input event and is scaled based on a arbitrary value. If you need to change the rate at which the camera rotates then change the value of the node that I commented “Speed of rotation”.

Camera Zoom

This code is very similar to the code above it. Instead of changing the rotation, I instead change the length of the spring arm component. This shortens or lengthens the distance that the camera is away from the player making it appear as if the camera is zooming in on the player. If you want to change the rate of the camera zoom, just change the value in the node that I commented “Speed of Zoom”.

Important Note: I did make the code frame-rate independent, but this might not be necessary because I am unsure whether or not the axis values from input nodes are frame-rate independent.

I know that this was a long one, but I hope it helps you out. Leave a comment if you have any questions,

Farshooter

1 Like

Thanks a lot for the prompt reply Farshooter, that worked perfectly!
You sir, are a star! :slight_smile:

For anyone looking for the answer to camera rotation in UE4.10, it doesn’t look like there’s a CombineRotators function that allows you to blend floats with rotations. Solution below :wink:

Hey concrete_buffalo, i implemented a camera rotation using your solution above, and it worked very well.

I also tried to add another routine to adjust camera pitch, but ran into a problem. I made it exactly the same as the rotate one above, but with a different input and Y (pitch). Problem is, if i rotate the camera and hit the key for pitch, the swing arm still rotates relative to the world, and not the way it is currently facing. Everything tilts like crazy.

I’ve tried a bunch of things but i’m not sure what i am missing, any ideas?

Thanks guys just stumbled across this been looking for a good solution. Champions