Hello! I have been trying to get my camera to only move up in Y and i finally got it. But one issue still exists; the player pushes the camera up when it hits the middle of the camera and I want it to push the camera when it is almost at the top. Any suggestions?
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour
{
public Transform target;
[SerializeField]
private float xMin;
[SerializeField]
private float xMax;
[SerializeField]
private float yMin;
[SerializeField]
private float yMax;
void Start()
{
target = GameObject.Find ("PlayerOne").transform;
//player = FindObjectOfType<Movement> ();
//isFollowing = true;
}
// Update is called once per frame
void LateUpdate ()
{
float currentHeight = target.position.y;
if (currentHeight > yMin)
{
yMin = currentHeight;
}
transform.position = new Vector3 (Mathf.Clamp (target.position.x, xMin, xMax), Mathf.Clamp (target.position.y, yMin, yMax), transform.position.z);
}
}
if I write this instead the player moves the camera upwards when it is much lower than half the camera size but if i change it to -10 or -20 it still pushed the camera when it reaches the middle not the top.
float currentHeight = target.position.y + 10;