Answer the question
In order to leave comments, you need to log in
How to set camera threshold in Unity3D?
Good day, dear ones! I ran into a problem, maybe someone can give a link to the script or to tips, or to a specific lesson where exactly this matter can be studied. In general, the problem is that when you hang any main camera on a character, then some elements become visible that should not be visible. For example, a 2D game, I hang a camera on the character, everything is cool, she watches him, but. If the character approaches the edge of the map, let's say, the camera also moves behind him, and already sees everything that is outside the playing space. It's not cool, bro. As for a separate script with a camera, everything is OK, I found a lesson on this, but unfortunately not on the threshold of the camera, I will be grateful for help from experienced people.
Answer the question
In order to leave comments, you need to log in
And purely poraskin brains without lessons?
1) Here you have a camera that has a width Wcam, height Hcam, its Xcam and Ycam coordinates are also known.
2) The camera also has its position in space horizontally X and vertically
Y. Xcam and Ycam cameras are tied to the player's X and Y.
4a) There is a world, for example, a plane that also has its own coordinates and the start point XstartYstart and the end point XendYend are known.
4b) You can use some object, for example, create an object with coordinates in the world Xobj and Yobj.
5) Knowing all of the above, you can easily calculate that the algorithm is extremely easy to calculate and make the necessary changes.
6) Insert in the script where the equation "binding the camera to the player, i.e. X and Y cameras are attached to the X and Y of the player" is inserted in the form of conditions
6a) IF ( (Xcam + Wcam)>= Xend) THEN do nothing x. Similarly, checks are made for the remaining 3 sides of the screen.
6b) IF( (Xcam+Wcam)>= Xobj ) THEN do_nothing ELSE Xcam=X. Similarly, checks are made for the remaining 3 sides of the screen. The bonus is that you can set a lot of such points, for example, put it on the door and if the player opened the door, then the camera came after him.
* Optionally, instead of "THEN DO NOT DO ANYTHING ELSE" you can zoom in on the camera, for example, approach the door and the closer to it the closer the camera is without leaving the edge of the point / world.
PS lessons, tutorials and ready-made scripts are not made in order to take and misunderstand / copy-paste without looking, but in order to understand how it is done and works. Another case is if it is something extremely complex or takes an incredible amount of time (for example, to make a complex shader \ effect \ physical phenomenon, etc.). Everything else is the basic things of the school course, I note that the school and not the institute.
https://www.youtube.com/watch?v=DoDZuFNh4tw&t=720s
I think this will help you
Use Cinemachine , then you don't have to write any code. This video just shows how it works. And here you can see the official tutorial.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question