Forum rules - please read before posting.

Camera Constraint issue

edited January 2020 in Technical Q&A

Hi all,

I would like to associate a camera with the movement of my character. I associated a camera to my player, the camera follows the movements of the latter (direct input movement). However I would like to make sure that the camera does not overflow outside my scene. I looked at the different tutorials but I did not find answers to my problem.
if i use a GameCamera2D my player can't move anymore on the X axe.

Here a screen of my camera inspector : https://ibb.co/z5n8t05

Thanks

Comments

  • Hey there! I'm pretty sure the problem is that you're using the Main Camera, instead of adding a new GameCamera to your scene. The Main Camera isn't really supposed to be moved around, it basically manages the other cameras.

    The GameCamera 2D has a script that will let you "lock" the horizontal and vertical axes of the camera so it doesn't see beyond the edge of your background art. This is what you want.

    It's in the 2d tutorial at the bookmarked "Default Camera" 25:26

    Try following that again and don't forget to assign this new Camera to the 'default camera' slot at the top of your Scene menu.

    What do you mean by "my player can't move on the X axis?" if you have a GameCamera 2D?

  • Indeed - you should move the "Main Camera" object to the root level of the Hierarchy (or simply delete it and use the Scene Manager's "Organise scene objects" button to spawn a new one).

    Generally speaking, you should leave the MainCamera alone - and just rely on GameCameras instead. Place a new GameCamera2D in the scene, make it the default Camera in the Scene Manager, and find the "Horizontal movement" panel in it's Inspector.

    Uncheck Lock? and then check Constrain? when it appears underneath. By default, the camera's target will be the Player, and you can now tweak the values (follow speed, constraint limits) as desired.

  • edited January 2020

    I found where the problem came from, when i creat a new scene i structure my scene without folder and unfortunatly i delete my PlayerStart2D so my DefaultCamera Field was erase.

  • The "Default Camera" field is actually just a convenient way of affecting the "Camera" field in your scene's default PlayerStart.

    Deleting the PlayerStart will unset the field, though the camera will remain in the scene. Assigning a new default PlayerStart will allow you to re-assign the camera.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.