Hey, I’m using the third person template to create an endless runner-style game, and I’d like the camera to stay locked on the y-axis when the character switches lanes so that it keeps moving forward with the character, but won’t receive any input when hitting A or D, thus staying centered. I’ve tried numerous different solutions on here, but the camera stubbornly continues to follow the character.
How would I go about locking one of the camera axis’? Thanks in advance!
Edit: Thanks to @vicecore and @aNorthStar the problem has been solved! Here’s the final node setup in the character blueprint, in case anyone else is struggling with this (just ignore the couple of nodes that are hooked up between Event BeginPlay and Event Ticks that aren’t in aNorthStar’s instructions). Thanks for the help guys!
I assume you’re using the camera inside of your CharacterBP. By default this will lock to the player.
You may want to consider building a separate Camera BP, or use an exterior camera system to follow the player.
Another potential solution working inside the CharacterBP, is to create 2 more camera’s.
- to the player’s Left
- to the player’s Right
Then set up some logic to behave such as this…
-
if player is in right lane, switch to camera 1 - (left of player) - to keep a central view
-
if player is in left lane, switch to camera 2 - (right of player) - to keep a central view
Hope this helps !
I am, yeah. I did try to create a separate blueprint for the camera, but I haven’t yet figured out how to set that blueprint as the default camera to be used, and have it follow the character (I’m pretty new to blueprints). When I added the separate BP to the scene, it showed the camera in the bottom right corner as being viewed, but when I hit play, it would instead default to a first person view from the object in the character blueprint.
For the second solution, wouldn’t that still require the central camera to not be moving when the keys are pressed? Otherwise all 3 of those cameras, all being linked to the same character blueprint, would move all together?
I have a small update. I have a camera in the scene set up and working from a small set of nodes in the level blueprint editor (using the Set View Target With Blend node), I’m just not sure how to make it follow the character along that axis? Or, at least, make it move at the same increasing speed along the same axis, so it doesn’t technically have to follow the character or be locked on to
In the world outliner, drag your new level cam (new view target reference) on top of your character
Again - do this in the world outliner to “group” the 2 assets
Cam will follow player but remain stationary. I just tested this successfully
@vicecore is on the right track, I think the most attractive, simplest and performant way to do this is to :
Camera Rig BP – create a new actor class in BP, maybe call it “BP Camera Rig”… and attach a spring arm component to be the parent and add a camera component as its child. On the spring arm component, turn off use pawn control (on both spring arm and camera components) and inherit pitch / yaw / roll. As desired, angle the spring arm and camera, set the spring arm length, adjust the socket offsets as it suits you. Spring arm lag will nicely smooth the camera speeding up and down to follow the player position.
Player Pawn / Player Controller BP – In your player pawn actor class… with Spawn Actor From Class spawn BP Camera Rig in BeginPlay and create a variable a reference to this actor… use Set Target With Blend with a reference to self and the BP Camera Rig as the target (this ensures that the right camera is selected)… on Tick, Get Actor Location of self (i.e. player pawn) and Set Actor Location of the variable referring to BP Camera Rig. . this sets the world location of the player pawn and camera rig as the same.
if everything is set up right, this should work just fine. any issues, just post here
Hey, would you be able to post a couple of screenshots of the second part of this process (in the character blueprint)? I have the Camera Rig blueprint selected in Spawn Actor From Class, and a custom event hooked up (Event BeginPlay is in use already), but I’m not quite sure where to go from there. I’m also not sure how to create a variable referring to an actor?
Ummm I don’t think you’ll need a custom event to spawn your Camera Rig BP… you can chain events from Begin Play (and from Tick by the way)… in fact you’ll find this really useful.
To create a variable referencing the actor you spawned (i.e. your Camera Rig BP) you’ll see a small blue outgoing circle on the right of the node, right click on the option ‘promote to variable’ and name the variable as it suits you, like ‘Camera Rig’. Using on Tick and Set World Location with this target reference and Get World Rotation of your player pawn (target will be self, so you can leave this blank). Sorry, I’m a bit busy to do a screenshot right now.
Ahh, okay, I understand now. I just gave it a shot though, and the camera still refused to stay still. It follows the character BP, but it’s still moving left and right with when I hit A and D
oh yes… I forgot one key thing… break open the yellow Get Actor Location vector.… experiment with the 3 green wires representing float values (it’ll probably be x or y)… break open the Set Actor Location vector… plug X float into X (or Y into Y) and leave the rest unplugged…
Thank you so much man! Just hopped back on this morning and got it to work with your method! I really appreciate the help! I’m going to select yours as the right answer, and edit my original post with a screenshot of your node setup in case anyone else has a similar problem. Again, thanks!
@vicecore Thanks for the help! I appreciate it! The camera lock is working now. I used the separate camera blueprint that you suggested with aNorthStar’s blueprint setup
Excellent!
Just a couple of minor things I’d maybe suggest for tidiness… In Begin Play you could consider spawning the camera rig IMMEDIATELY at the player transform with Get Actor Transform. (btw a transform… if you split out the struct… consists of vector, rotation and scale). This would eliminate any jump between locations from Begin Play to when Tick takes effect… Id guess this jump is quite invisible but nonetheless.
Also, if you don’t need it… you can snip the Z float from the Set Actor Location… it will stop the camera moving vertically at all in world space… if you don’t need vertical camera movement it’s tidier and might be an invisibly tiny bit smoother.
By the way, to get some really nice smoothing as your character accelerates and slows, add some lag to spring arm component (just position lag, you won’t need rotation lag because the camera doesn’t rotate). For extra smoothness, I’d open the advanced settings and turn on lag sub stepping and set the interval to as low as possible). As players, we may never notice your smooth cam, but I really believe we FEEL it
This is a really good solution but it cost a little bit because you are calling Set Actor Location at each frame