You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
647 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DynamicCamera : MonoBehaviour
  5. {
  6. public GameObject target;
  7. public float camHeight;
  8. void Start()
  9. {
  10. }
  11. void Follow()
  12. {
  13. Vector3 tempDest = target.transform.position;
  14. camHeight = target.transform.localScale.magnitude;
  15. tempDest -= transform.forward * camHeight;
  16. Vector3 destination = Vector3.Lerp(transform.position, tempDest, 10f * Time.deltaTime);
  17. transform.position = destination;
  18. }
  19. // Update is called once per frame
  20. void FixedUpdate()
  21. {
  22. Follow();
  23. }
  24. }