Camera yMin postion should be restricted to player postion
hi I am developing an android game where a player jump upon taping and the camera follows the player. what I did is I restricted the camera on lowest vertical position which is yMin = 0; and yMax into 2. the camera follows player smoothly. But now what I want is that when player changes its position, camera position changes and update the lower limit yMin to present postion of player. So that if player falls below the seen the camera don't follow to the initial value I set. here is my code for camera follow.
public class CameraFollow : MonoBehaviour {
[SerializeField]
private float yMin;
[SerializeField]
private float yMax;
[SerializeField]
private float xMin;
[SerializeField]
private float xMax;
private Transform target;
void Start () {
target = GameObject.Find("Player").transform;
}
void Update(){
}
// Update is called once per frame
void LateUpdate () {
Vector3 targetPos = new Vector3 (
Mathf.Clamp(target.position.x, xMin, xMax),
Mathf.Clamp(target.position.y, yMin, yMax),
-10
);
transform.position = Vector3.Lerp(transform.position, targetPos, 0.02f);
if (Input.GetKeyDown(KeyCode.Escape)){
Application.Quit ();
}
}
}
android unity3d
Your answer
Follow this Question
Related Questions
Let the Camera Face the middle of the Map while still following the Player? 1 Answer
Unity: How to move the Camera by a certain amount? 1 Answer
How can I use clicked position for an object and camera movement at he same time? 2 Answers
Sharing ints,Camera position(MOba),warnings,Could loop a fuction in start??? 0 Answers
Camera zoom out on follow 1 Answer