Unity camera following and camera boundary (Cinemachine)

1 package

1. Open Package Manager in the Unity Editor (menu: Window > Package Manager)
Insert image description here

2. Find the Cinemachine entry and click Install in the lower right corner.
Insert image description here

2.Cinemachine settings

1. To start using Cinemachine, you need to add the Cinemachine 2D camera to the scene by selecting the Cinemachine > Create 2D Camera entry on the top menu bar.
2. A new game object named CM vcam1 (representing Cinemachine Virtual Camera 1) will be created at this time.
Insert image description here

4. Follow the protagonist

1. Pull the protagonist directly into Follow to let the camera follow the protagonist
Insert image description here

5. Camera Boundary
1. To add Cinemachine Confiner, go to the bottom of Virtual Camera Inspector, click the Add Extension drop-down menu, and select CinemachineConfiner:
Insert image description here
2. Boundary settings are as shown below
Insert image description here
3. Drag it into the virtual camera
Insert image description here

Guess you like

Origin blog.csdn.net/qq_60839745/article/details/129250473