Как сделать чтобы машина ехала туда, куда смотрит?
Делаю простую игру в Unity, понадобилось реализовать механику поворота. Движение вперед-назад я сделал, поворот модели машины тоже есть, но она продолжает двигаться только по оси Z. Как можно это исправить?
Код:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Player : MonoBehaviour
{
[SerializeField] KeyCode keyOne;
[SerializeField] KeyCode keyTwo;
[SerializeField] KeyCode keyThree;
[SerializeField] KeyCode keyFour;
[SerializeField] Vector3 moveDirection;
private void FixedUpdate()
{
if (Input.GetKey(keyOne))
{
GetComponent<Rigidbody>().velocity += moveDirection;
}
if (Input.GetKey(keyTwo))
{
GetComponent<Rigidbody>().velocity -= moveDirection;
}
if (Input.GetKeyUp(keyThree))
{
GetComponent<Rigidbody>().MoveRotation(Quaternion.Euler(0f, -10f, 0f));
}
if (Input.GetKeyUp(keyFour))
{
GetComponent<Rigidbody>().MoveRotation(Quaternion.Euler(0f, 10f, 0f));
}
}
}