Camera movement not restricting with clamp
I am building a load runner type game. The Camera is made a child object under the player. The player can move till -19.5 and 16 on x axis and 3 and 17.9 on y axis. The camera should follow (center) the player but should stop centering the player or move beyond the given x values or end of the scene built. But the camera is moving beyond the scene to show empty spaces. The camera is clamped in the player script as follows
void Start()
{
cam = GameObject.FindGameObjectWithTag("Player").transform.GetChild(0).gameObject;
Vector3 v3 = cam.transform.position;
v3.x = Mathf.Clamp(v3.x, -19.5f, 16f);
v3.y = Mathf.Clamp(v3.y, 3f, 17.9f);
cam.transform.position = v3;
rest of the code ,.... }
Your answer
Follow this Question
Related Questions
How to move camera in x-z axis only for RTS touch script for mobile ? 0 Answers
If Scene come to 20 second, first camera change other second camera 2 Answers
Cinematic Camera Movement 0 Answers
Rotate object to be between camera and center point 0 Answers
C# 360 Orbital Camera Controller (Gimbal Lock Issue) 1 Answer