/
vasandi
/
AirSim
Обзор
Документация
Войти
/
vasandi
/
AirSim
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Unity/UnityDemo/Assets/AirSimAssets/Scripts/SmoothFollow.cs
42 строки
1 KB
Андрей Васильченко
сборка под ubuntu 26.04
08 июл 2026, 10:15
08 июл 2026, 10:15
d53c5a2
Код
Авторство
О чём код?
using UnityEngine; public class SmoothFollow : MonoBehaviour { public bool shouldRotate = true; // The target we are following [SerializeField] private Transform target; private float wantedRotationAngle; private float currentRotationAngle; private Quaternion currentRotation; private Vector3 offsetPostion; private void Start() { offsetPostion = new Vector3(0, 5, -10); } private void LateUpdate() { if (!target) { return; } // Calculate the current rotation angles wantedRotationAngle = target.eulerAngles.y; currentRotationAngle = transform.eulerAngles.y; // Damp the rotation around the y-axis currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, 0.3f); // Convert the angle into a rotation currentRotation = Quaternion.Euler(0, currentRotationAngle, 0); // Set the position of the camera on the x-z plane to: // distance meters behind the target transform.position = target.position + (currentRotation * offsetPostion); // Always look at the target transform.LookAt(target); } }