Lock a camera behind character (Ball template)

Hello good people, i was wondering if there is any way to lock a camera behind the character, meaning you can NOT walk towards the camera (like in the thrid person template) ?

I am trying to create a game where you play as a spere racing around, but the camera set-up is really wonky for this as is, so i would like the camera to react to the “forward” motion of the sphere, always giving you a view of whats in front of you.

I have tried multiple ways in the “Ball template”, but noone seems to work.

Perhaps its just as wise to start from a first person template and just offset the camera and change the character?

Any input would be appreciated!

Just curious, how do you want your camera to behave when the player presses ‘down’ on the thumb stick? Instead of rolling backward toward the camera, what do you want to happen?

To be honest, it’s just a school project, so its more about learning - hence i don’t really need inputs for a stick (i think?)

Simply using w,a,s,d and space for this one

Okay, great. Learning is always a good reason to experiment and ask questions. I’m happy to help.

So let me rephrase my question, and then explain why I’m asking.

What do you want to happen when you press the ‘S’ key? Normally, for a third-person view, this is the “move backward” (toward the camera) button. If you don’t want your pawn to be able to move toward the camera, what should the ‘S’ key do? Nothing? Or…

If I sound confusing with that question, let me ask a different one. When you say the pawn “can NOT walk towards the camera”, do you mean that you just don’t want the pawn to turn and face the camera? But the pawn is still allowed to move toward the camera by moving ‘backward’? (This makes more sense for a humanoid character, which has a front and a back, but is harder to imagine when your pawn is just a sphere, which looks the same from every direction.) Is this closer to what you have in mind?

I just want to make sure I can picture what your desired result is before I try to answer your questions and provide suggestions.

This is weird and terrible - but it might help you get started!

Starting from another template is probably the way to go - rolling ball template is kinda wonky to begin with. (No stable forward vector on this pawn is why I needed to base it off of velocity instead of just “what direction are you facing”)

Aha! I see what you are saying now, and i see how my explaination was bit off!

I dont think i would actually need an S key at all for this type of game, but if i were to have one, i would like it back up towards the camere like a car in a racing game, so yeah, no facing the camera, always looking ahead to the ongoing “track”! If that made more sense :stuck_out_tongue:

Alright, that does not seem too bad!

Then i have a start, from 3d person temp, -swap character - and with physics, you mean enable physics and then use thrusters oor? (I have’nt really set up a controlsystem like this from scratch before)

Okay, now I understand. Thanks!

The part I missed was that you want the camera to always rotate and point in the direction that the ball is moving. That’s entirely doable.

In this case, I’m glad I asked about the backwards (S) key because you probably will need to disable it, or at least change it into a brake-like button (that slows your pawn down). This is because, if you allow it to move your pawn backwards, the camera will need to quickly rotate 180 degrees, which would then change the backwards vector, which would change the movement vector, which would change the camera’s rotation, which would change the backwards vector, and so on, and so on. So making your ‘S’ key into a braking (slow-down) button is the way to go. Just something to be aware of.

As for how to implement this, it looks like O may have already offered a starting point. The thing to realize about his suggestion is, you’ll need your pawn to be using physics forces (which you probably want anyway) for movement so that setup can work. This type of pawn movement will resemble the Roller Ball template — but only in that way. Your camera system is still closer in style to the Third Person template. In other words, if you start with the Third Person template, you’ll need to create your own ball pawn blueprint, if you haven’t already.

Wow, that is absolutely amazing! Great result (I especially like the effect when it bounces into things, neat!) Thanks so much for the quick answers and the detailed walkthrough, i might just have learned something today! :smiley:

Here’s my take on how the whole thing would work. It builds upon what O wrote, but also includes Pawn movement and a smoothly interpolated camera. Hopefully you find it useful.

I started with the Roller Ball template and just modified a couple of things within. I guess I kind of went against what we discussed earlier, because I didn’t use any assets or scripting snippets from the Third Person template. (I didn’t even open that template at all.) So if you’re starting from the Roller Ball template, you can follow these steps and arrive at the same result I did.

Once you start up your Roller Ball template, the only asset that needs to be modified is the ball pawn blueprint. The default name for this asset is ‘PhysicsBallBP’ but I made a duplicate and renamed it ‘BP_CustomPhysicsBall’. The name isn’t important, but I wanted to clarify in case the name in the screenshot is confusing.

You’re going to modify the template’s behavior for the ball’s left/right and forward/back movement. Here’s what my graph looked like after I made the modifications:

Left-right movement nodes:

And now, the forward-back movement nodes:

If you compare those screenshots to the template’s original setup, you’ll see the primary difference is we’re using the camera’s current view direction to determine into which directions the ball should roll when A/D and W/S are pressed. Instead of just rolling into the world’s fixed X axis (for left/right inputs) and Y axis (for forward/back inputs), as the template does, we’re creating vectors that point into the camera’s forward and right directions.

That’s all there is to getting the ball to move relative to the camera’s current orientation, but the result right now won’t seem any different than the template default. This is because the camera isn’t rotating yet, and the camera’s forward and right vectors are (more or less) aligned with the world X and Y axes. So the next step is to implement the camera rotation stuff.

The following screenshot shows how I implemented the camera orientation behavior. You’ll have to add all of these nodes in yourself if you’re using the Rolling Ball template. Have a look and try setting this up in your project:

I commented a few nodes, so I hope it makes sense without much more explanation. But take special note of that RInterpTo node, which adds some real nice smoothness magic to the camera rotation. Without this interpolation node, the camera would be glued rigidly to the ball’s velocity direction. With the node, the camera turns gently, which feels much better. As an added bonus, this interpolation of the rotation negates the need to disable the ‘backward’ input like I suggested earlier; with this node, moving backwards is not a problem and, in fact, works great for improving control of the ball. Cool!

If you want to adjust the speed of the rotation smoothness, feel free to tune the ‘Interp Speed’ parameter on that node. Smaller values result in a slower camera turn.

Hopefully this helps you understand how these elements work together, and hopefully it creates the effect you want. Let us know if you have any more questions!

1 Like

Niceeeeee!