Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraController : MonoBehaviour {
- // Define el objetivo al que sigues
- public GameObject target;
- // Parametros del seguimiento
- public float distance, height, angle;
- // Control de posicion de la camara
- private Vector3 position;
- // Use this for initialization
- void Start () {
- // Deten la ejecucion en caso de error de target
- if (target == null) Debug.LogError("Target no asignado");
- }
- // Update is called once per frame
- void LateUpdate () {
- // Mueve la camara
- MoveCamera();
- }
- // Posicion la camara detras del objetivo
- void MoveCamera() {
- // Calcula la altura
- position.y = (target.transform.position.y + height);
- // Calcula la posicion detras del target
- angle = (Mathf.Deg2Rad * (target.transform.localEulerAngles.y - 180));
- position.x = ((Mathf.Sin(angle) * distance) + target.transform.position.x);
- position.z = ((Mathf.Cos(angle) * distance) + target.transform.position.z);
- // Coloca la camara
- this.transform.position = position;
- // Haz que la camara mire al target
- this.transform.LookAt(target.transform.position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement