True racing AI is quite hard, mainly because it requires a control system with a feedback loop. One of my biggest regrets was a project I looked at, which was far too complex for me to handle at the time, with racing AI.
Line-following is generally good because it’s stable and predictable. But, if you feel like finding a more detailed solution, there are a few articles around that can get you started.