Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FollowCamera : MonoBehaviour
- {
- public float FollowSpeed = 0;
- public float RotateSpeed = 200;
- public static FollowCamera cam;
- public Transform Player, Enemy;
- public Vector3 Offset = new Vector3(-6, 2, 2);
- public Vector3 Velocity;
- public Vector3 LOffset;
- public float MinDistance = 5, MaxDistance = 100;
- void Start()
- {
- }
- void Update()
- {
- if (Player != null && Enemy != null)
- {
- this.transform.position = Vector3.SmoothDamp (this.transform.position, Player.transform.position + Offset, ref Velocity, FollowSpeed);
- var distance = Vector3.Distance (Enemy.transform.position, Player.transform.position);
- var targetDirection = Enemy.position + LOffset - this.transform.position;
- targetDirection.y = 0.00F;
- var targetRotation = Quaternion.LookRotation(targetDirection);
- var deltaAngle = Quaternion.Angle(this.transform.rotation, targetRotation);
- Offset.z = distance;
- Offset.x = distance;
- Offset.z = Mathf.Clamp(Offset.z, -MinDistance, MaxDistance);
- Offset.x = Mathf.Clamp(Offset.x, -MinDistance, MaxDistance);
- print("La distancia es " + distance.ToString());
- if (deltaAngle == 0.00F) {
- return;
- }
- this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRotation, RotateSpeed * Time.deltaTime / deltaAngle);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement