🆙Use in your code

You can call public props and methods in the Drive component from your own components.

Here is an example of how you can use the Drive component to create your own car controller:

public class Controller : MonoBehaviour
    {
        public float inputV = 0f;
        private float inputH = 0f;
        private bool inputSpace = false;
        private Drive drive;

        private void Start()
        {
            drive = GetComponent<Drive>();
        }

        void Update()
        {
            inputV = Input.GetAxis("Vertical");
            inputH = Input.GetAxis("Horizontal");
            inputSpace = Input.GetKey(KeyCode.Space);

            drive.forward = inputV > 0;
            drive.backward = inputV < 0;
            drive.brake = !drive.backward ? inputV < 0 : false;
            drive.angleToPosition = inputH * drive.maxSteerAngle;
            drive.stop = inputSpace;
        }
    }

(this code is included in the asset in CarAI/Scripts/Player/Controller.cs)

Here are some references that you can use in your code

In CarAI/Scripts/Core/Drive.cs

Public properties
  • forward : bool (make the car move forward)

  • backward : bool (make the car move backward)

  • brake : bool (make the car brake)

  • stop : bool (make the car stop)

  • angleToPosition : float (make the wheels turn to the angle you provide)

  • speed : float (return the current speed of the car)

In CarAI/Scripts/AI/Sensor.cs

Public properties
  • obstacles : List<GameObject> (return the list of current obstacles triggered by the sensor)

  • obstacleOnFront : bool (return true if the sensor is detecting an obstacle on front)

  • targetIsCar : bool (return true if the current target is a car / false if it's a waypoint)


Public methods
  • getClosestTarget() : Transform (return the nearest Waypoint transform from the sensor/car)

Last updated