Welcome to the adventure of programming evolutionary artificial neural networks! In this blog post, we will guide you through the exciting process of implementing a car simulation using Unity, where cars learn to navigate through different courses using a feedforward neural network. Buckle up and let’s dive in!
The Simulation
Picture this: you have a fleet of autonomous cars trying to make their way through a challenging course without bumping into walls or obstacles. How do they achieve this? Each car is equipped with five front-facing sensors that measure the distance to objects around them. Think of these sensors as the car’s eyes, helping them “see” the road ahead to avoid collisions.
Each sensor covers a range of approximately 90 degrees, with a maximum sensing distance of 10 Unity units. The readings from these sensors become the input for the neural network, which eventually decides how much force to apply on the engine and the steering.


Setting Up the Neural Network
At the core of our simulation is a fully connected feedforward Neural Network, structured into four layers:
- An input layer with 5 neurons (the sensors’ readings)
- Two hidden layers with 4 and 3 neurons
- An output layer with 2 neurons (for steering and acceleration)
To check out the code for the Neural Network, visit: UnityProjectAssetsScriptsAINeuralNetworks.
Training the Neural Network
Now comes the fun part: training the neural network with a Genetic Algorithm! Imagine a unique breeding program where we create a batch of cars, train them to navigate the course, and then select the best performers to create the next generation. Here’s how it works:
- Initially, spawn N randomly initialized cars.
- Select the best cars based on performance.
- Recombine them to create new offspring, injecting random mutations to keep things exciting.
- Evaluate the new population and repeat the process.
This entire cycle from evaluation to the next generation is known as a “generation.” For further modification of the Genetic Algorithm, check out: UnityProjectAssetsScriptsAIEvolutionGeneticAlgorithm.cs for the generic version.
User Interface
The user interface is designed to keep you informed about the best car’s status:
- Top-left corner: Neural Network output (engine and turning actions)
- Just below: Evaluation value (percentage of course completion)
- Bottom-left corner: Generation counter
- Upper-right corner: Current best car’s Neural Network weights, color-coded based on the weights’ value
All UI code can be found at UnityProjectAssetsScriptsGUI.
Choosing Your Course
The simulation comes equipped with various courses of differing difficulty levels. Look for them in the directory: UnityProjectAssetsScenesTracks. To start a specific course, access the Main scene and enter the scene name in the Inspector of the GameStateManager object.

Troubleshooting Your Simulation
If you face issues during the simulation or while modifying the parameters, here are some troubleshooting tips:
- Ensure Unity is properly configured and check your project settings.
- Look out for any console errors that may indicate code issues or missing assets.
- Try resetting the UI components if they don’t display correctly.
- For any persistent problems, consult the documentation or reference guides related to Unity or Neural Networks.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
Now, go ahead and unleash the power of AI with your own car simulation project. Happy coding!

