Control the car with arrow-keys

Seems like a lot of ML projects centre around self-driving cars in top-down game environments. This is a car class that attempts to capture some realistic steering behaviour. Give it a go! The car turns red when it loses traction, indicating some skidding/drifting. The car turns white when it regains traction and steers “normally.” Obviously it’s still not a very realistic model (the car can spin in place!) but I think it’s useful for a bit of fun.

Using the class (p5.js)

Copy car.js into your p5 project directory and create a car in your script:

car = new Car(); // Initialises car in the middle of the canvas.
// OR
car = new Car(x, y, angle); // Initialises car with desired location, angle

you need to call the following once every loop through draw() .

car.update(); // simulates the car;   // renders the car

If you want to change how the car is controlled (eg. by some neural network) you will have to modify the update() function in car.js