• News

• Industries

• Learning & Support

• Community

• Marketplace

# Creating a sidescrolling camera that leads the player

Hello people!

I’m trying to mix things up and i’m wanting to create a camera that will lead the player slightly when they move from left to right so they can see whats coming up.

I made a camera lag blueprint based on a blueprint from elsewhere and i’ve been trying to modify it to suit my needs but I’m having a bit of trouble making it do what I want.

Here is the existing blueprint and camera setup. The project is a sidescroller platformer 2.5D kinda thing.

and just incase my english is letting me down, heres an illustration!

Thanks everybody.

I’ve been tinkering some more but not having any luck, anyone want to chip in?

You’ve got a camera boom for one thing. To illustrate: http://www.porta-jib.com/vz-side.jpg That’s a camera boom. Think of it like a big rod that holds your camera in a fixed position relative to the other end of the rod. And your camera boom is fastened to your character. That means your camera, as it stands, will never move relative to your character.

I don’t know why you’re spawning a camera in the blueprint, I don’t quite understand what you’re doing with that.

So one possible solution would be set the camera a distance away from the character based on their current velocity. If they’re velocity is 0, the camera is right on them. If it’s >0, it’s to the right, and it’s <0 it’s to the left. If this is too herky jerky, you could simply interpolate between two values, thought that might not work as well for the second one.

Another possible solution would be to use the “Pressed” and “Released” events for, lets say, the D and A key. If they Press D, it adds to the Camera’s length from the character (so that the camera is to the right) if they Release D it subtracts that same amount. Then the same for the A key. The reason you’d want to add and subtract instead of a fixed length is in case they hit both A and D simultaneously. (In this case, it would cancel each other out and stay in the middle.) Or if they hit A to D in the same frame. (That way you don’t have to predict which order it’ll be in.)

What you could do is to animate the camera boom itself. What I’m thinking of is to add a parent component to the camera boom, then you just move that component using a InterpTo handling the current the target position with a nice interpolation, when you press right you set that target position right using a relative offset. In your tick you will the just adjust the new parent (or the boom if you want) to have the interpolated relative transform. The applies to the left movement (just inverse all :D). If you release all keys you just set that target position back to the initial relative transform (0,0,0 I guess), so having the InterpTo in your tick your camera should smoothly go back to the initial position.

The offset could be based on your speed and depending on that you could also push the camera out a bit, this will give you a ‘faster’ sense of your movement, also adding a nice motion blur Post Process effect could be good.