3D Platformer Camera?

Hello, I’ve decided to pick up and learn Unreal Engine 5 as a hobby, and while I only started a couple days ago I’m really enjoying it, and have been adding to the 3rd Person Template from the starter pack. I have already added a doublejump feature as well as moving platforms using Splines.

I am currently attempting to update the camera so that it behaves similarly to cameras in 3D platformers such as Mario or Ratchet and Clank, but so far I have had little success, and I’ve been unable to find any examples or tutorials on how to go about achieving this anywhere.
Here is a gif from what I have set up that might help with my explanation:

The red sphere is a sort of ‘anchor point’ i want the camera to focus on. It will always follow the player’s X and Y axes but I want its Z-coordinate to stick to the player only when they are, for example, standing on a moving platform and going up, when the player is running up a slope, when they are falling from a height, or when the player jumps and they are above/on top of a new platform.

Anyone know how I may set about doing this? I am using blueprints for the time being.

Imagine a game like Planet Coaster or Roller Coaster Tycoon where you can pan the camera and orbit the location you wish. You can do this by making the pawn you possess a Blueprint that only contains the camera. The player character can just be a ref that the isolated camera pawn sends inputs/controls to. Then make the camera pawn use your X/Y (red sphere) as desired for Set Actor Location. This might also be possible by making a scene component your root but that isn’t how character base classes come out of the box.

1 Like

Excuse my late reply, I wasn’t able to respond 'til just now.

I tried around with that for a while, but had no success unfortunately.

But I learned about line traces so I’m experimenting with that right now, and so far it’s working fairly well.

Still having a few hiccups, for example, I want the sphere (the camera’s ‘Z-anchor’ I’m calling it for now) to automatically lerp up on top of the platforms (to roughly where the sphere’s Z-center would sit in the middle of the player) if the line trace finds a “hit” with a platform below the player, and for the sphere to continue moving up/down the slopes even if the player is jumping.

I Will continue working on this, but if others have more advice or feedback on how I may fix these lesser issues I’m all ears. Thanks to everyone for taking your time to read this and offer help, btw.


EDIT: Made some more progress. It almost works exactly how I want it to now

The red sphere follows me when i walk up and down slopes as I want, and if i’m above a platform the red sphere lerps to the top of the platform approximately to where the center of my character will be. But it still jitters a bit when standing on a moving platform that moves up really fast, and it also skips up a bit when I jump up slopes, and it doesn’t move down when I jump down slopes.

My math is probably just wrong somewhere in there.

Would like to see your blueprint or c++. It’s looking awesome!

Played around with the idea a bit… just as an option, this is what I ended up with:


image

Updated the post… woke up at the middle of the night remembering there was a node for this… :sweat_smile:

2 Likes

Played around some more, and really cleaned my blue print up. It’s even closer, but still not perfect:

The primary issues now are the jitteriness when the player falls and when the palyer is moving up or down on a fast platform as shown in the gif. It also tends to sink into the ground when going up.

The camera’s Z anchor point also skips a little whenever i jump up a slope.

Other than these hiccups it’s working very well I think for now. Once I iron out the jitteriness and the camera sinking into the floor while going up moving platforms, then I’ll be able to make the actual camera start focusing on the sphere’s Z-coordinate rather than the player’s.

Here is my blueprint, by the way:

I apologize for the whitespace in bits and pieces. I’m unsure how to capture a full screenshot of my BP, so i took screenshots piece by piece, and then put them together lol

2 Likes

Another update:
Almost got it perfect:

Only issue now, as y’all can see, is the camera spring arm causes the camera to momentarily clip into the walls whenever i jump up onto a platform. Otherwise it’s perfect now.

Anyone got any advice on how I can make the camera spring arm not force the camera to clip into the wall/ground while the camera Z-coordinate interpolates up to the player?

1 Like

You could set the SpringArm DoCollisionTest based on parameters like how close the camera is to the lerp target.

1 Like

That worked, thanks :+1:

I think I finally have what I set out to do at the beginning. Basic behavior is functioning virtually exactly as I wanted it to:

Camera can still clip into the ground if the pitch is really low, but it’s very minor, and I think I can find a way to work around that.

Spring arm is a little too snappy (when it zooms in/out on the player) but that’s a topic for another discussion.

Thanks everyone who lent a hand in this endeavor, I think I can say this question is now resolved for the time being.

3 Likes

Hi there,

First off, sorry for necro-ing this post. I’ve been trying to implement a 3D platformer camera like this and these are the only public examples of how it’s done that I’ve found. I was gonna make a separate question referencing this one but decided it’d be better to keep it all in one place in case someone else wants to do something similar and is struggling like I currently am.

But to get to the point, I’ve been following along with the blueprints shared here and am struggling to dissect and understand how the “anchor point” works and how you guys have managed to keep the camera focused on that “anchor point” while the playercharacter jumps for a few days now.

  • My initial assumption was that the camera followed the spheretrace/debugsphere itself and that’s how the “anchor point” effect happened, so I tried these a few times
    • Plugging the blueprints onto the player character itself at first, that didn’t work
    • Plugging it into an actor component and attaching that to the playercharacter
    • Creating a custom camera component, plugging the blueprint info there, and attaching that to the spring arm.
  • Then I tried creating a separate pawn that’s set to keep the same relative location as the playercharacter and attach the spring arm and custom camera component to that.

But no matter what I’ve tried, the camera won’t focus on anything but the playercharacter as they jump. I’m still relatively new to Unreal, so I’m sure there’s something simple that I’ve missed/don’t understand, so I’d appreciate some help understanding how this all works.

did you ever figure it out?