What do i need to change in my code so the camera is going to follow the player smoothly?
here is the code
var player : GameObject;
function Update()
{
this.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x, player.gameObject.transform.position.y+6, this.gameObject.transform.position.z);
}
This is another camera follow script that works well.
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject followTarget;
private Vector3 targetPos;
public float moveSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
targetPos = new Vector3 (followTarget.transform.position.x, followTarget.transform.position.y, transform.position.z);
transform.position = Vector3.Lerp (transform.position, targetPos, moveSpeed * Time.deltaTime);
}
}