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 Z-axes?

I am trying Side Scroller game. When player jump, camera also do jump. I don't want to do that.

I read some answers, and moved camera component between character mesh and spring arm. But its not working for me.

When I set Absolute Position then camera doesn't follow character.

How to lock camera?

Product Version: Not Selected
more ▼

asked Jun 01 '15 at 04:34 AM in Blueprint Scripting

avatar image

75 22 19 24

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

2 answers: sort voted first

Find somewhere in player code/blueprint vector operations like player_position + offset = camera_position. After that operation you need to get camera world position, set Z to some constant number, and then set camera world position with this vector. That's all.
There is actually big number of ways to do this. Solution above is simple and pretty fast.
How to:
This is not code, it all can be done in blueprints.
Ouch, this is uses spring arm, didn't know it.
But anyway I've created side scroller and opened character blueprint.
pic Then in blueprint created Event Tick (called every frame). Notice, that in spring arm properties in the right side there is Traget Offset. If we can see variable - then we can use it!
Then I made variable for camera's height.
Dragged spring arm to event graph, then dragged node, in search printed "Offset" and chosed "Set Target Offset".
Doing all the same with other components do something like this:
This is easy scalar (not actually vector) calculations, you'll figure out :-)
And viola! Try this out, it works, but i'am out of attachments here. And yeah, you need to turn off "Do Collision Check" in spring arm settings, or camera will sometimes go into walls.

1.jpg (65.5 kB)
2.jpg (800.1 kB)
3.jpg (68.1 kB)
4.jpg (340.5 kB)
5.jpg (172.9 kB)
more ▼

answered Jun 01 '15 at 06:06 AM

avatar image

495 29 24 40

avatar image yogesh_gamer Jun 01 '15 at 07:14 AM

It sounds really simple. But I don't have knowledge of Coding. I'm doing all stuffs with Blueprints. And I can't find something like "player_position + offset = camera_position" in Details of Character. Can you show me how to do this via blueprint.

avatar image HungryDoodles Jun 02 '15 at 10:31 AM

Updated my answer, now with tutorial :-)

avatar image ravio Jan 28 '16 at 06:29 AM

@HungryDoodles Would you mind if I used your blueprint in a game I am making. I would likely be selling the game I would use it in. Please reply.

avatar image HungryDoodles Jan 29 '16 at 08:29 AM

Of course you can, I don't even know the reason why you can't use it :-)

avatar image ravio Feb 08 '16 at 06:00 PM

Thank you so much I plan to use a variation of it in my game. How should we credit you if you wish to be credited or would allow us to?

avatar image ravio Feb 08 '16 at 06:01 PM

As like a special thanks or something like that

avatar image HungryDoodles Feb 10 '16 at 02:58 PM

No need to, it's simple little blueprint, not a plugin or a module. Just 1 arithmetic operation and 2 vectors, my real code takes about ~150 lines of C++ for a one task. :-) (Too many happy faces!) It's OK, really.
But if you insist, so my nickname HungryDoodles is used everywhere, feel free to credit it.

avatar image CBALZ Jul 16 '16 at 11:21 AM

This works for other axis as well, not just horizontal axis. Just change the break vector component & make vector component to the axis you want affected. I didn't want my camera to move horizontally while I moved. thanks HungryDoodles really simple and helpfull.

avatar image yogesh_gamer Jun 02 '15 at 11:55 AM

Thank You Sir. It worked. But I wish there were some very simple methods in "Details". Where we have to just tick or untick and then Bingo. :D

Thanks Again for detailed tutorial. Marking as answer. :)

avatar image Ghostblades Oct 15 '15 at 08:01 PM

This worked for me as well, but is there any way to do this so that you could actually get the camera to unlock when you go downwards and lock back up? or would the camera have to transition to a different camera - if lets say you want to climb down a ladder or up to a high place thats above? So that the camera follows you but then stays at that level until you come back down

avatar image HungryDoodles Jul 16 '16 at 03:15 PM

Simply triggers. Create blueprint inherited from trigger or empty blueprint. In second case add some primitive that will check for player pawn. When event OnComponentOverlap (primitive) is triggered you need to cast Other actor to your pawn class (where fixed Z code is) and change it's CameraHeight variable to what specified in your trigger as another variable (let's call it Camera Desired Height). You can put any amount of triggers and from inside level editor change their Camera Desired Heights to what needed in different places.
If you want disable Z fix than you need to create boolean variable to use it as switch. You need a Brunch (blueprint node) by this bool where on False Target Offset needs to be zero vector (set to 0,0,0) and on True use Z-fixing. Enabling/disabling is similar to above with triggers.

avatar image AJ_Graphix Jan 31 '17 at 06:43 PM

Thanks so much, HungryDoodles, for this fantastic solution!! :-)

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

I've just done something similar for a twin-stick shooter game I am working on. I want the spring arm and camera attached to the back of the player actor, however I want the camera to aways points towards positive X (north). I simply turned off "Inherit Yaw" in the Spring Arm properties and that did the trick:

alt text

capture.png (5.1 kB)
more ▼

answered Nov 29 '15 at 09:45 PM

avatar image

194 10 18 26

(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