Skip to content

Instantly share code, notes, and snippets.

@blenderdeluxe
Created June 22, 2017 21:58
Show Gist options
  • Save blenderdeluxe/06e102af0623c29528884df0871e312a to your computer and use it in GitHub Desktop.
Save blenderdeluxe/06e102af0623c29528884df0871e312a to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public GameObject target;
// Use this for initialization
void Start () {
target = GameObject.Find("Player");
}
// Update is called once per frame
void Update () {
Vector3 velocity = Vector3.zero;
Vector3 forward = target.transform.forward * 10.0f;
//Posicion objetivo
Vector3 needPos = target.transform.position - forward;
//SmoothDamp recibe la posicion actual de la camara, la posicion objetivo, la velocidad, y el smoothTime
transform.position = Vector3.SmoothDamp ( transform.position, needPos, ref velocity, 0.08f );
transform.position = new Vector3( Mathf.Clamp(transform.position.x, 121, 445), Mathf.Clamp(transform.position.y, 115, 130), -20);
transform.rotation = target.transform.rotation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment