public class PlayerController : MonoBehaviour
{
[SerializeField] float speed; // add value in the inspector (about 20)
[SerializeField] float turnspeed; // add value in the inspector (about 50)
float horizontalAxes;
float verticalAxes;
void Start()
{
}
void Update()
{
horizontalAxes = Input.GetAxis("Horizontal");
verticalAxes = Input.GetAxis("Vertical");
//slides car to the sides
//transform.Translate(horizontalAxes * Time.deltaTime * turnspeed * Vector3.right);
//rotates car
transform.Rotate(Vector3.up, horizontalAxes * Time.deltaTime * turnspeed);
transform.Translate(speed * Time.deltaTime * verticalAxes * Vector3.forward);
}
}
Dodatkowo możemy dodać skrypt do kamery aby podążała za samochodem
public class FollowPlayer : MonoBehaviour
{
[SerializeField] GameObject player;
[SerializeField] Vector3 offset;
void Start()
{
}
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
}
Podstawowy ruch samolotu na wprost z rotacją góra dół
float speed = 2f;
float rotationSpeed = 80f;
float verticalInput;
void Start()
{
}
void FixedUpdate()
{
verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * speed);
transform.Rotate(Vector3.right * rotationSpeed * Time.deltaTime * verticalInput);
}