Вращение камеры
Добавлено: 14 апр 2021, 16:36
Всем привет! Пишу управление камерой, но тормоза происходят на самых элементарных вещах. Нужен поворот вокруг своей оси на 360 градусов по осям XY (Ну обычное FPS управление), но на кнопках(В теории это типо летает космический корабль). Сделал. Камера вертится. Но когда камера принимает положение "вверх ногами" управление влево вправо инвертируется. Или же просто описывает восьмерку.
Вообще не понимаю как убрать это. Подскажите как это исправить
Вообще не понимаю как убрать это. Подскажите как это исправить
Синтаксис:
Используется csharp
public class Player : MonoBehaviour
{
public float RotationSpeed = 120;
private float CurrentRotationSpeedX = 0;
private float CurrentRotationSpeedY = 0;
private Rigidbody m_rigidbody;
void Start()
{
m_rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, -RotationSpeed, Time.deltaTime * 3);
}
else if (Input.GetKey(KeyCode.S))
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, RotationSpeed, Time.deltaTime * 3);
}
else
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, 0, Time.deltaTime * 4);
}
if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, -RotationSpeed * sign, Time.deltaTime * 3);
}
else if (Input.GetKey(KeyCode.D))
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, RotationSpeed * sign, Time.deltaTime * 3);
}
else
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, 0, Time.deltaTime * 4);
}
transform.RotateAround(transform.position, transform.right, CurrentRotationSpeedX * Time.deltaTime);
transform.RotateAround(transform.position, Vector3.up, CurrentRotationSpeedY * Time.deltaTime);
}
}
{
public float RotationSpeed = 120;
private float CurrentRotationSpeedX = 0;
private float CurrentRotationSpeedY = 0;
private Rigidbody m_rigidbody;
void Start()
{
m_rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, -RotationSpeed, Time.deltaTime * 3);
}
else if (Input.GetKey(KeyCode.S))
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, RotationSpeed, Time.deltaTime * 3);
}
else
{
CurrentRotationSpeedX = Mathf.Lerp(CurrentRotationSpeedX, 0, Time.deltaTime * 4);
}
if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, -RotationSpeed * sign, Time.deltaTime * 3);
}
else if (Input.GetKey(KeyCode.D))
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, RotationSpeed * sign, Time.deltaTime * 3);
}
else
{
CurrentRotationSpeedY = Mathf.Lerp(CurrentRotationSpeedY, 0, Time.deltaTime * 4);
}
transform.RotateAround(transform.position, transform.right, CurrentRotationSpeedX * Time.deltaTime);
transform.RotateAround(transform.position, Vector3.up, CurrentRotationSpeedY * Time.deltaTime);
}
}