Rotate and zoom camera in top down template?

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