Let's start by creating the interface to control the car. This interface is a MonoBehaviour class with public members, so the player and the agents could interact with it easily and seamlessly:
- Create a new file and name it CarController, as shown in the following code:
using UnityEngine;public class CarController : MonoBehaviour{ // next steps}
- Next, define the member variables, as follows:
public float speed;public float maxSpeed;public float steering;public float maxSteering;public Vector3 velocity;
- Implement the Update for making it run and steer:
private void Update(){ transform.Rotate(Vector3.up, steering, Space.Self); transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.World);}
Now, we will also ...