Advertisement
onzulin

ThirdPersonCamera

Sep 22nd, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ThirdPersonCamera : MonoBehaviour
  6. {
  7. //offset va a ser la distancia entre la camara y la esfera que es nuestro player
  8. public Vector3 offset;
  9. private Transform target;
  10. [Range(0,1)] public float lerpValue;
  11. public GameObject Player;
  12. public GameObject referencia;
  13. public Vector3 distancia;
  14. public string controlInvertido;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. target = GameObject.FindWithTag("Player").transform;
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update()
  23. {
  24.  
  25. }
  26. //Método de Unity que lo que hace es ejecutarse al final de cada fotograma
  27. private void LateUpdate()
  28. {
  29. transform.position = Vector3.Lerp(transform.position, target.position + offset, lerpValue);
  30. transform.LookAt(target);
  31.  
  32. //Eje Y vista izquierda y derecha
  33. // Tengo que arreglar esto para el principio Don't Repeat your self
  34. offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * 2, Vector3.up) * offset;
  35. transform.position = target.transform.position + offset;
  36. transform.LookAt(target.transform.position);
  37. /*
  38. offset = Quaternion.AngleAxis(Input.GetAxis("Joystick 4") * 2, Vector3.up) * offset;
  39. transform.position = target.transform.position + offset;
  40. transform.LookAt(target.transform.position);
  41. */
  42. //Eje X vista hacia abajo y arriba
  43. offset = Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * 2, -Vector3.right) * offset;
  44. transform.position = target.transform.position + offset;
  45. transform.LookAt(target.transform.position);
  46. Debug.Log("vista eje X: " + offset);
  47. /*
  48. offset = Quaternion.AngleAxis(Input.GetAxis("Joystick 5") * 2, -Vector3.right) * offset;
  49. transform.position = target.transform.position + offset;
  50. transform.LookAt(target.transform.position);
  51. */
  52. //referencia para que los controles esten bien rotados
  53. Vector3 copiaRotacion = new Vector3(0, transform.eulerAngles.y, 0);
  54. referencia.transform.eulerAngles = copiaRotacion;
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement