For fun i started learning about reinforcement learning, and started to experiment with Unity mlagents toolkit.

I initially ran into issues installing ML-Agents on my Mac Silicon M4, so I followed the guide by Jack McKew, which was incredibly helpful in getting my setup running.

At first, my car agent kept getting stuck, especially around the same region, and it would repeatedly collide with obstacles instead of finding alternative routes. To address this, I experimented with several strategies:

Obstacle Awareness:
Used a RayPerceptionSensorComponent3D with 20 rays over 180° for better obstacle detection, replacing manual raycasts for more reliable input.

Reward Shaping:
Gave rewards for reducing distance to the target, with a bonus for alignment toward the goal—guiding the agent to move efficiently.

Stuck Penalty:
Added a penalty if the agent made little progress over time, encouraging exploration instead of repeated collisions.

Sequential Rewards:
Designed 6 reward checkpoints before the final goal. Dying before reaching them triggered a penalty based on missed rewards, pushing the agent to fully complete the task.

By mixing these strategies, like only using few, and commenting out the code for others to see which was effective, I finally managed to tweak the system so the car would successfully navigate around obstacles and reach the goal consistently.

More Projects