Camera Change

Hello!

I’m creating a 2D game and I wanted to develop a style of camera like when the character leaves the edge of the screen, or touches the end of the screen, the camera changes to the next position… Like: Sem-t-tulo hosted at ImgBB — ImgBB


If the player touch the trigger the camera goes to the next location, but, if the player goes back the camera returns… I tried to create one and searched for a solution but I haven’t found anything…

Glad for the help! <3

Oh I was kind of using a method like that, so maybe I can help
Are you using CineMachine?

I tried to use it, but since I’m a beginner I don’t have the knowledge to use it :frowning:
I’ll try and see somithing on CineMachine

Create your camera boxes.

Vector2[] cameraBoxes =
new Vector2[2] {new Vector2(0,0), new Vector2(1000,0)};

Create your trigger boxes.

Vector4[] triggerBox =
new Vector4[2] { new Vector4(500,0, 50,100), new Vector4(550,0,50,100)}; //x,y,width,height

Then check if your player is in the trigger box for left[0] or right[1] and move the camera to cameraBoxes[desiredCameraBoxIndex].

I’ll try it tomorrow, I’ve never seen Vector4 or read about it so I’ll search first in Unity Documentation and try to use/understand & apply ^^

I was just using it as a simple way to hold more values because you need a width and height to create a box(V4.xyzw). So I am using the z and w to hold width and height.

I used CineMachine! Pretty simple to use and easy learning ^^
But thanks too adehm, I’ll try your solution later too! Thank you very much.