Z
Z
Zefirot2021-09-20 11:27:32
C++ / C#
Zefirot, 2021-09-20 11:27:32

How to set correct camera borders?

Recently I tried cinema machine, but it has flaws at least for my movement option, in general I returned with the standard camera movement and focus adjustment.
The problem is only with the indication of boundaries, I have movement in 2D in all directions plus focus, the boundaries are set by a 2D collider

float BoundSizeX = LevelPrefab.gameObject.GetComponent<BoxCollider2D>().size.x;  
float BoundSizeY = LevelPrefab.gameObject.GetComponent<BoxCollider2D>().size.y; 
float BoundOffsetX = LevelPrefab.gameObject.GetComponent<BoxCollider2D>().offset.x;  
float BoundOffsetY = LevelPrefab.gameObject.GetComponent<BoxCollider2D>().offset.y; 
float maxY = BoundOffsetY + (BoundSizeY / 2f);
float minY = BoundOffsetY - (BoundSizeY / 2f);
float minX = BoundOffsetX - (BoundSizeX / 2f);
float maxX = BoundOffsetX + (BoundSizeX / 2f);

But firstly, in this way, the borders climb halfway, and secondly, with focus, they climb or crawl out even more.
How to set the boundaries so that when the camera moves, it rests on the boundaries of the collider, and also does not climb out when the focus is on?

Ps - the cinema machine is not suitable in my case, sticking when going out of bounds, jerks ... in general, the question is without it ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question