How to make the camera collide with the edge in 2D
Hi there I am making a 2D platformer, I am having trouble with being able to have my camera collide with the edge once it has reached it, so far I have been unsuccessful and have read many articles and tried a lot of code but none of the article codes that I have gotten have helped me with this problem. Here is my camera script which I use:
using UnityEngine;
public class CameraFollow : MonoBehaviour { [SerializeField] private Transform target; [SerializeField] [Range(0.01f, 1f)] private float smoothSpeed = 0.125f; [SerializeField] private Vector3 offset; private Vector3 velocity = Vector3.zero;
private void LateUpdate()
{
Vector3 desiredPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, desiredPosition, ref velocity, smoothSpeed);
}
}
I hope that somebody can help me with this I would much appreciate it thanks.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613021021im_/https://answers.unity.com/themes/thub/images/avi.jpg)