Advertisement
Diamond32_Tutoriales

CamaraTipoDBZ budokai tenkaichi

Sep 12th, 2021
1,528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class FollowCamera : MonoBehaviour
  6. {
  7.     public float FollowSpeed = 0;
  8.     public float RotateSpeed = 200;
  9.  
  10.     public static FollowCamera cam;
  11.  
  12.     public Transform Player, Enemy;
  13.     public Vector3 Offset = new  Vector3(-6, 2, 2);
  14.     public Vector3 Velocity;
  15.     public Vector3 LOffset;
  16.     public float MinDistance = 5, MaxDistance = 100;
  17.    
  18.     void Start()
  19.     {
  20.        
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         if (Player != null && Enemy != null)
  26.         {
  27.             this.transform.position = Vector3.SmoothDamp (this.transform.position, Player.transform.position + Offset, ref Velocity, FollowSpeed);
  28.             var distance = Vector3.Distance (Enemy.transform.position, Player.transform.position);
  29.             var targetDirection = Enemy.position + LOffset - this.transform.position;
  30.             targetDirection.y = 0.00F;
  31.            
  32.             var targetRotation = Quaternion.LookRotation(targetDirection);
  33.             var deltaAngle = Quaternion.Angle(this.transform.rotation, targetRotation);
  34.  
  35.             Offset.z = distance;
  36.             Offset.x = distance;
  37.             Offset.z = Mathf.Clamp(Offset.z, -MinDistance, MaxDistance);
  38.             Offset.x = Mathf.Clamp(Offset.x, -MinDistance, MaxDistance);
  39.            
  40.             print("La distancia es " + distance.ToString());
  41.             if (deltaAngle == 0.00F) {
  42.                 return;
  43.             }
  44.  
  45.             this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRotation, RotateSpeed * Time.deltaTime / deltaAngle);
  46.            
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement