1. Home
  2. Explore
  3. Computer Science
  4. Trackmania AI and Noseboost

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Trackmania AI and Noseboost

Transcript

This is me, racing against an Artificial  Intelligence, in the game Trackmania. But wait! You might be a bit confused by what just happened. Why is this AI driving like that? And how is it so fast? To understand, we need to rewind a bit more. Actually, I've been working  on this AI for many years now. This computer program is designed to learn  the game from scratch, entirely on its own. And with enough training, it managed  to drive with incredible precision,

master drifting, even drive on pipes. The thing is... All of this is kinda outdated now,  for a pretty unexpected reason. In recent years, a revolution  happened in Trackmania, when some players discovered that driving on all  four wheels is actually not optimal in this game. Using custom tools, they found that instead, it's faster to drive on the nose. By exploiting a glitch called the noseboost. When driving in this position, it can  trigger a bug in the game's physics, which suddenly pushes the  car speed to its maximum. This is extremely hard though, no  human can do that in real time. But what about my AI? Can it learn to control this  bug? To drive like that? Well, I've spent almost a year  trying to answer that question. And the journey all started here, on this  small training track, with a simple plan.

You see, this noseboost trick  might seem really complicated. But it's nothing more than a way to build  up speed. That's what we care about. So to make the AI learn to noseboost,   my plan is to simply train it to  get as much speed as possible. And to guide the AI towards this  goal, I'm gonna give it rewards. For each action it takes, the AI gets  a reward equal to its current speed. Its only goal then is to predict the  actions that add up to the most rewards.

And it learns this through a process  called Reinforcement Learning. Basically, the AI starts with  zero knowledge of the game. And to improve, it's gonna  drive this track many times. With each attempt, it can try new  things, learn from its mistakes,   and gradually develop its own driving strategy. This strategy is directly linked  to how it perceives the game. To select its action, the AI can observe a few  dynamic properties of the car. Like its velocity, rotation and wheel information.

Now with enough trial and error learning,   we just have to hope the AI comes up with  a clever strategy to gain speed quickly. Hopefully using the noseboost. Actually, the AI is training on a  track that should encourage that. With this jump. It's specially designed to  make the car land on its nose. However, the AI doesn't seem to care. After a few hours of training, it just  found a way to cancel the car's rotation, land on its four wheels, and safely correct rewards like that.

Even with more training, the  AI never changed its approach. But honestly, I'm not too surprised. It was pretty unlikely to randomly  stumble upon a noseboost like that. If we want the AI to discover  something more advanced, it's gonna need a bit more guidance. So the next day, I tried something different. First, I drove a run myself. Up to this point. Now, the AI is gonna play from here. In this new training session,

the AI is forced to try driving on its  nose. And after a few random attempts, it already found something interesting. Not a noseboost, but a nosebug. A small bug in in the game which  can produce a sharp turn when you   both accelerate, steer and brake vertically. On its own, this trick isn't  really useful for gaining speed. But the AI is on the right track here. Because if you ever chain several nosebugs, then  the car speed can magically start to skyrocket. There it becomes a noseboost.

All of this needs to happen extremely fast. Way too fast for any human player. It shouldn't be a limit for our AI though,  it can take 100 actions per second. So let's see what it can  achieve with more training. Well, it didn't go as planned. The AI quickly realized that it could simply  slide upside down, and collect rewards like that. Ok maybe it was just bad luck. So I've  tried to restart the training a second time. And this time, the AI came  up with a different strategy.

But again, it fooled me. It just found  a way to land on all four wheels,   to easily collect its rewards. Apparently, the AI really doesn't  want to drive on its nose. So I'm gonna force it. With one new rule. Now, while the AI is driving, I'm  gonna track how vertical its car is. As soon as it starts tilting too  much, the AI gets no more rewards. The run ends there. in the same way, I'm also gonna  measure the height of its car. If it goes too high, no rewards again.

With these new constraints,   the AI is forced to keep balanced on  its front wheels, to drive on its nose. Let's see what it can do in  this new training session. Did you see that? Here. This time, I think we got a noseboost. Yeah this looks good. For the first time, the AI  got a noticeable speed gain. This is not a complete noseboost, the  car didn't reach its maximum speed. But it's a great start. At least, the AI finally discovered  the key to bigger rewards. Now, the training should  start getting interesting. Well again, things didn't go as expected. After some time, the AI completely  stopped trying to noseboost.

Instead, it just learned to balance on its  front wheels, without trying to gain speed. I have to admit, it's pretty good at this. But it's weird, the AI discovered the noseboost. It knows it could get higher rewards with it. Yet, it choses a different strategy. Can you guess why? I think the AI is afraid of risk. So far, I've rewarded the AI  based on its current speed. So at the start of each attempt,  it gets mid-range rewards. With a noseboost, it could  potentially double that.

But as speed increases, the car's  behavior becomes harder to predict.   Just one mistake and the reward stopped there. Instead of taking that risk, the  AI probably learned it's better to   aim for smaller rewards, as long as it  can accumulate them over a longer time. But I think we can easily fix this. By shifting the rewards like this. Now, if the AI doesn't take more  risk, it's not gonna gain much. But if it starts a noseboost,  the gain will be massive.

This is not a big fix. Just one small change  in the AI code, among thousands of other lines. Yet, it changed everything. This is what we want. Now, the AI is no longer afraid to take risks. Now it's clearly trying to gain speed by all  means, even if it leads to the end of the run. Until finally.. The AI did it. For the very first time, it  achieved a complete noseboost. But was it just luck? Has it  truly learned this technique? After letting the training run a  bit longer, this is what I got.

Ok now we can say it: the AI learned to noseboost! Something no human can do. Arguably the hardest trick in this game. And its progress doesn't stop there. Now that the AI can reach the game's maximum  speed, it looks like it's targeting a new goal. After launching a noseboost, it's now trying to  sustain it for a few extra tenths of a second. This is where it gets interesting: can it find  a way to sustain the noseboost indefinitely? To keep driving at this speed?

Could it even follow a road like that? Across an entire track? As training progresses, the AI is  getting better and better attempts. But its progress is a bit slow,   it seems to be really struggling  to stabilize the car at this speed. After countless hours of training, it still hasn't  found a consistent way to sustain the noseboost. Only for about 2 seconds at best, still not enough to cover an entire track yet. But I think it's a good start!

In just about a week, I've  already made a lot of progress. Now it's probably down to  fixing a few more details,   before the AI can keep a  noseboost going endlessly. It shouldn't be too much work to get  there, just a few more days to fix this.. Right? That was 9 months ago. Now editing this video, I realized that back then, I was a bit naive. In the following days, I kept trying to  adjust the rewards in different ways. But the AI still couldn't  maintain a noseboost for long.

So I tried to tweak other things,  like how it perceives the game. It wasn't better. Day after day, I kept adjusting some  training parameters here and there,   hoping for an improvement. Until the end of April, when the AI got this run. 3 seconds. After several weeks, that  was the best it could do.

At this point, I was really starting to doubt. Is it even possible to do better? I mean, we are really pushing the  game's physics to the edge here. Can you really predict, in real time,  how these bugs are gonna behave? As the car gains speed, its  movement becomes quite chaotic. It almost feels random. Or maybe these behaviors are predictable,   but there's something wrong with  the way I'm training the AI. I already tried to adjust many small  things, but if the AI is still struggling,

it might point to a deeper  problem in the way it's learning. As I was stuck with these doubts, I decided  to forget about the noseboost for a while,   to focus exclusively on the AI's learning setup. For that, I went back to a more standard track, where it was easier to  benchmark the AI's learning, and where I knew for sure  it could still be improved. That's when I went down a bit of a rabbit hole. Spending weeks testing different training methods,

most of them led to nowhere,  or just raised more questions. Which made me try even more approaches. But once in a while, I would  find something valuable. The AI's training would improve. But not as much as I expected. So I kept experimenting, searching for new ideas, looking at similar projects for inspiration. And slowly, it led to new advances, which I shared proudly on my Patreon page. But then, there was Linesight. A similar AI project released around this time.

Its impressive performance made me realize there  were still things I needed to fix in my own AI. So I kept trying new techniques, taking  inspiration from Linesight's code. And slowly, the progress continued,  it was starting to look pretty good. But there were still a few unanswered questions. A couple more ideas to try. Just a few more weeks of research, right? This whole process was getting tiring though. It wasn't easy to stay motivated. So I also spent time on other  projects, and eventually, just enjoyed the rest of summer. For the first time in 5 months, the  noseboost idea crossed my mind again. By this point, I had made several core  changes to the training algorithm. And overall, it made the AI much more  efficient at learning the game now. But was that enough to keep  control of a noseboost? This was the moment of truth. I restarted a final training  session on this track.

I let it run overnight and the next  morning, I came back to see the results. This is what I got.

This time the AI did it. It found a way to maintain  control of the noseboost, to keep driving at the game's maximum speed, almost indefinitely. This opened up a whole new field of possibilities. But at this point, something  else was catching my attention. Why these circles? It looks like the AI wants to  stay in the center of the stadium,  as if it's afraid of crashing into the boundaries. But the AI can't even see the  stadium, so that's not the reason.

I've run several other training  sessions out of curiosity. And for some reason, the AI didn't  always come up with the same strategy. I also got the triangle strategy, the star strategy, the zigzag strategy and this AI, which doesn't seem to have any strategy. It's just moving around randomly. At least it shows that the AI has  some flexibility in its movement. But is it enough to control where it's going? For that, we can use a simple test.

Now, I'll give the AI additional rewards when  it's moving in the direction of this target. I'm also giving the AI new  inputs to localize the target. Let's see what it can do with a bit more training.

Ok it's doing great! The AI can steer the noseboost. Its driving often looks a bit hesitant though,  it's not moving as smoothly as I expected. So I let the training run a little longer. And when I came back a few hours  later, this is what I found. Yeah I didn't expect this!  The AI changed its strategy. Now it doesn't crash into the pillar  anymore, it's maintaining a safe distance. Which makes sense: this way it  can accumulate more rewards. Wait! This gives me an idea. I'd like to try something out, just for fun. In a few seconds, I'm gonna direct  the AI towards this new location. Can it adapt?

Yeah it's working great! The AI can definitely control its movements. And its driving looks smoother than before. Seeing this, I think we can still  challenge this AI a little more. It's time to get back to the serious stuff. I think the AI is ready to  face its final challenge. One track, 30 corners. Can the AI complete this with a single  noseboost all the way to the finish? Overall, the training method  remains the same here. At first, I'm just rewarding the  AI when it gains enough speed.

Until it learns to noseboost properly. Once it's confident, I'm replacing  this signal with a new one, that only rewards the AI when it's  making progress along the road. I also gave the AI additional inputs  to help it locate itself on the track. Now let's see how the training goes. It's looking good so far, the AI seems  to understand what it needs to do. And the pace at which it's driving is just absurd. It's fast, but it's not super consistent.

Along these corners, the AI is struggling  to keep control of the noseboost. And I feel like many of these  mistakes are pretty similar, happening when the car stops spinning. Up until now, the AI has kept  doing these spinning movements. I guess it's necessary to  keep it balanced on its nose. Almost like it's turned into a spinning top. But for some reason, it seems harder  to keep that spin going on this track. To understand why, I looked at how  fast it's spinning during a run.

And if you pay close attention, you  might start to notice a pattern. Every time the AI makes a right  turn, it increases the spin. But when it turns the other  way, it tends to cancel it out. When the AI had more space,   it could sustain the spin by turning  in the same direction over and over. I think it was the reason  behind the circle strategy. But to follow a road, it has to turn  both ways, which looks a bit trickier. But I don't think we need to  worry too much about that.

Because at this point, the AI  is still making some progress. Over time, it's getting better at chaining left  and right turns while maintaining the spin. Slowly, it's getting closer to the finish. With its current level, it should  be able to reach it eventually. Now it's probably just a matter  of a few thousand more attempts.. Right?

After learning to trigger a noseboost, to sustain it, and to control its direction, the AI mastered this technique well enough  to complete an entire track with it. Beating my personal time here by about 25 seconds. And if the AI achieved all of that, it's  partly thanks to one important thing: those who support this project on Patreon. Because the whole process behind this  kind of video takes a huge amount of time,   any support on Patreon really helps  me to keep this project going.

So if you'd like to help me make more videos,  you can consider subscribing to my Patreon. In exchange, you'll get access to extra content,   like these five bonus clips  I couldn't fit in this video. You can visit this page for more info. Now speaking of future videos, there's still one  thing we need to clear up about the noseboost. These runs. Several times in this video,  I've shown this footage of   noseboosts which were not done by my AI. And as I said, humans can't do that either.

So you might have been  wondering, who is driving here? Well nobody. Nobody is making real-time  decisions to control the car here. This are Tool Assisted Speedruns. Basically, a Tool Assisted Speedrun  is a pre-recorded list of actions,   which has been carefully crafted by humans,  often with the help of programming tools. This can result in strategies that are far more  advanced that what my AI does, for many reasons. But I won't dive into that today, because that's what I want to  explore in my next AI video. Until then, don't hesitate to visit my  Patreon if you'd like to support this work. And if you just want to know  when the next video comes out, you can simply subscribe for free to this channel.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent