Answer the question
In order to leave comments, you need to log in
How to setup camera for TopDown 2D game?
We have some kind of location, a character is moving on it, the camera is attached to it, moving accordingly, the camera has maximum and minimum values so that textures outside the location are not shown, as soon as the character approaches one of the location boundaries, the camera stops, moreover, the character can go further, BUT if you change the resolution from 16:9 (1920x1080) to 4:3 (800x600), then the camera does not reach the border it needs, is it possible to solve this or is it easier to complete a couple of textures outside the location and set the maximum and minimum camera value is bigger
1920x1080
Game
Scene
800x600
Game
Scene
Short video - https://www.youtube.com/watch?v=AewMkNubhYA
Camera settings Camera
script
public class CameraController : MonoBehaviour
{
public Transform target;
public float smoothing;
public Vector2 maxPosition;
public Vector2 minPosition;
void Start()
{
transform.position = new Vector3(target.position.x,target.position.y,transform.position.z);
}
void LateUpdate()
{
if(transform.position != target.position)
{
Vector3 targetPosition = new Vector3(target.position.x, target.position.y, transform.position.z);
targetPosition.x = Mathf.Clamp(targetPosition.x, minPosition.x, maxPosition.x);
targetPosition.y = Mathf.Clamp(targetPosition.y, minPosition.y, maxPosition.y);
transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing);
}
}
}
Answer the question
In order to leave comments, you need to log in
You have a minimum and maximum position for one resolution, and put another. Either set this data directly at once, or count at the start. By the way, targetPosition is better to create at the start
Unity has a handy plugin for the camera - cinemachine.
It also allows you to limit the out of bounds space so that the character does not enter the game space.
Another way is easier.
You do not connect any plugins, you leave everything as it is. You just place invisible walls around the perimeter, beyond which the player will not go beyond the space. Profit
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question