Готовый перевод C# Game Programming Cookbook for Unity 3D / Программирование игр на Unity 3D C#. Книга готовых решений.: 4.6.1 Камера от третьего лица
Ниже скрипт Camera_Third_Person:
public class Camera_Third_Person : BaseCameraController
{
public Transform myTransform;
public Transform target;
public float distance = 20.0f;
public float height = 5.0f;
public float heightDamping = 2.0f;
public float lookAtHeight = 0.0f;
public float rotationSnapTime = 0.3F;
public float distanceSnapTime;
public Vector3 lookAtAdjustVector;
private float usedDistance;
float wantedRotationAngle;
float wantedHeight;
float currentRotationAngle;
float currentHeight;
Quaternion currentRotation;
Vector3 wantedPosition;
private float yVelocity = 0.0F;
private float zVelocity = 0.0F;
public override void SetTarget( Transform aTarget )
{
target= aTarget;
}
void LateUpdate ()
{
if ( target == null )
return;
if ( myTransform==null )
{
myTransform=Transform;
}
wantedHeight = target.position.y + height; currentHeight = myTransform.position.y;
wantedRotationAngle = target.eulerAngles.y; currentRotationAngle = myTransform.eulerAngles.y;
currentRotationAngle = Mathf.SmoothDampAngle(currentRotation
Angle, wantedRotationAngle, ref yVelocity, rotationSnapTime);
currentHeight = Mathf.Lerp(currentHeight, wantedHeight,
heightDamping * Time.deltaTime);
wantedPosition = target.position; wantedPosition.y = currentHeight;
usedDistance = Mathf.SmoothDampAngle(usedDistance, distance,
ref zVelocity, distanceSnapTime);
wantedPosition += Quaternion.Euler(0, currentRotationAngle,
0) * new Vector3(0, 0, -usedDistance);
myTransform.position = wantedPosition;
myTransform.LookAt( target.position + lookAtAdjustVector );
}
}
Внимание! Этот перевод, возможно, ещё не готов.
Его статус: идёт перевод
Переведено на Нотабеноиде
http://notabenoid.org/book/55263/242470
Переводчики: ilia1395
Настройки
Готово:
