123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SmoothFollowCShap : MonoBehaviour
- {
-
-
-
- public Transform target;
-
- public float distance = 10.0f;
-
- public float height = 5.0f;
-
- public float heightDamping = 0.5f;
- public float rotationDamping = 0.3f;
- private float _RefRotation = 0f;
- private float _RefHigh = 0f;
-
- void LateUpdate()
- {
-
- if (!target)
- return;
-
-
- float wantedRotationAngle = target.eulerAngles.y;
- float wantedHeight = target.position.y + height;
- float currentRotationAngle = transform.eulerAngles.y;
- float currentHeight = transform.position.y;
-
- currentRotationAngle = Mathf.SmoothDampAngle(currentRotationAngle, wantedRotationAngle, ref _RefRotation, rotationDamping);
-
- currentHeight = Mathf.SmoothDamp(currentHeight, wantedHeight, ref _RefHigh, heightDamping);
-
- Quaternion currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
-
-
- transform.position = target.position;
- transform.position -= currentRotation * Vector3.forward * distance;
-
-
-
-
- transform.LookAt(target);
-
- }
-
- }
|