How do I go about creating a camera that follows the currently possessed pawn?
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 the camera to follow the player on x and y only. I do not want the camera to go up and down everytime the player jumps
2) I need the camera to follow the currently possessed pawn. I have vehicles in my game which the 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 the camera to the currently possessed pawn and want to ignore the pawns rotation in all axes and the scale in the z axis. I am trying to create a GTA 2 style camera http://youtu.be/MaBlgdox6-Q?t=1m
I guess as a bonus question, how would I get the camera to lead the player when they are inside a vehicle like in the video?
Any help is much appreciated! :)
Though I imagine you're not using the Top Down template, you might want to take a look at the camera settings for the MyCharacter Blueprint in that template. Having a Spring Arm component with Absolute Rotation instead of Relative will maintain the x and y position of your camera even if your character rotates.
To keep the 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 the sub-class camera rather than to every vehicle individually. If you set the camera up the same as you have it for your character, changing possession to a car from your character will maintain the same view.
To get your camera to lead the vehicle, you'll need to do some blueprint work inside your vehicle sub-class. You can Lerp the camera component to a position in front of the vehicle, and Lerp to new positions as the car is rotated. You'll need to experiment with this to get it to look and feel the way you want it.
Jumping and maintaining the same camera z position is somewhat more complicated, and may involve a few different methods depending on how you're setting up your game. The problem is that if you're using the built in Character class for your character Blueprint, the Jump command actually moves the whole character capsule and the camera with it. You can write your own jump functionality so that it only moves the character mesh instead of the 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 the camera cannot pass above it. Enable Do Collision Test in the 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.
answered Jul 08 '14 at 11:14 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here