using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// private variables
private float speed = 10.0f;
private float turnSpeed = 25.0f;
private float horizontalInput;
private float forwardInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
// moves the car forward based on vertical input
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
// rotates teh car based on horizontal input
transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed * horizontalInput);
}
}
Like this:
Like Loading...
Related