How do I go about creating a camera that follows currently possessed pawn?

Hello,

I am trying to create a camera for my top down game. It is not a point and click strategy game. I am trying to achieve a couple of different things here

  1. I need camera to follow player on x and y only. I do not want camera to go up and down everytime player jumps

  2. I need camera to follow currently possessed pawn. I have vehicles in my game which player can possess. I do not want to have a camera for each and every vehicle that I need to modify. I would like to have a global camera that does this.

Is it possible to create such a camera in blueprints without having to use “Set Actor Location” because that introduces a lot of jerkiness when moving around.

Basically I want to attach camera to currently possessed pawn and want to ignore pawns rotation in all axes and scale in z axis. I am trying to create a GTA 2 style camera GTA... 2 - YouTube

I guess as a bonus question, how would I get camera to lead player when they are inside a vehicle like in video?

Any help is much appreciated! :slight_smile:

1 Like

Hey ,

Though I imagine you’re not using Top Down template, you might want to take a look at camera settings for MyCharacter Blueprint in that template. Having a Spring Arm component with Absolute Rotation instead of Relative will maintain x and y position of your camera even if your character rotates.

9869-absoluterotation.jpg

To keep same camera set up for each vehicle, you can create your own vehicle sub-class with a specific camera, and then derive each different car type from that class. Then you’ll only need to make adjustments to sub-class camera rather than to every vehicle individually. If you set camera up same as you have it for your character, changing possession to a car from your character will maintain same view.

To get your camera to lead vehicle, you’ll need to do some blueprint work inside your vehicle sub-class. You can Lerp camera component to a position in front of vehicle, and Lerp to new positions as car is rotated. You’ll need to experiment with this to get it to look and feel way you want it.

Jumping and maintaining same camera z position is somewhat more complicated, and may involve a few different methods depending on how you’re setting up your game. problem is that if you’re using built in Character class for your character Blueprint, Jump command actually moves whole character capsule and camera with it. You can write your own jump functionality so that it only moves character mesh instead of whole character, but that may lead to collision issues with your levels if jumping is anything more than aesthetic, and may involve significantly more work to function correctly. An easier option is to create a Camera Blocking Volume above your level directly above your desired camera height so that camera cannot pass above it. Enable Do Collision Test in Spring Arm component and you’ll get what you’re looking for… but this will only work properly if your camera is directly above your character.

Hope all that helps! Let me know if you have more questions.

1 Like

That is a fantastic response. Thanks ! I did manage to solve this problem a different way (all three of them) and will post my version of it up here soon after I do some clean up and comment it. I found this easy to manage but I do not know how efficient it is, but it works for me.