x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to lock camera y-axis so it only moves forward?

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! :) alt text

Product Version: UE 4.22
Tags:
camera-rig-lock.png (265.0 kB)
more ▼

asked Jun 13 '19 at 10:30 PM in Blueprint Scripting

avatar image

theROFLpacman
57 1 3 4

avatar image vicecore Jun 13 '19 at 11:29 PM

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. 1) to the player's Left 2) 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 !

avatar image theROFLpacman Jun 14 '19 at 12:33 AM

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?

avatar image theROFLpacman Jun 14 '19 at 12:53 AM

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

avatar image vicecore Jun 14 '19 at 01:09 AM

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 alt text

avatar image theROFLpacman Jun 14 '19 at 02:44 AM

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

avatar image theROFLpacman Jun 14 '19 at 02:57 PM

@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

avatar image aNorthStar Jun 15 '19 at 12:24 AM

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 :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

@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 :)

more ▼

answered Jun 14 '19 at 01:24 AM

avatar image

aNorthStar
1.1k 9 17 21

avatar image theROFLpacman Jun 14 '19 at 02:20 AM

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?

avatar image aNorthStar Jun 14 '19 at 02:44 AM

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.

avatar image aNorthStar Jun 14 '19 at 03:26 AM

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....

avatar image theROFLpacman Jun 14 '19 at 02:44 PM

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! :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question