what is it in racing game code that so often results in the car rapidly spinning and flying around colliding into everything?

418 views

seems like every game with a car has this happen occasionally, and I was wondering what the underlying theme is in how vehicles are coded in these games that makes it such a common glitch?

[example](https://v.redd.it/w1qkg6qji2ca1)

In: 5

5 Answers

Anonymous 0 Comments

Game physics engines have to be imprecise for several reasons, but importantly they have to work in with snapshots. In reality, as far as we know, things move with infinite precision. When things collide they go from being apart to hitting smoothly. But in a game, if there are two objects moving towards each other then one moment they’re apart and the next they would be **overlapping**.

When things overlap the game has to figure out how to deal with it. One way is to force them apart and with speed based on how far they overlapped. Imagine you have two really strong magnets pointed the wants-to-push-apart direction. You probably can’t make them touch just by forcing them together. But what if they magically teleported right next to each other? They’d go flying away at high speed, right?

So one way they get big forces applied is by the engine trying to untangle objects that somehow ended up way overlapping (and how this can happen is also a bit complicated).

Why does that make them spinny? Well things get spinny when you hit them on the edge and not the center (sorta, this is a simplification). But if you’ve ever spun a bicycle wheel you know how you hit it a bunch of times on the edge to make it spin fast, right? Well, now you combine the thing I said before about objects getting pushed away real fast, except instead of away you get a push on an edge like that and it goes super spinny.

Now everything I’ve said is a simplification. And physics engines all have different details about how exactly they do these things. But the approximation of collisions combined with working with framerates is a big part of why things go wrong in this particular way.

You are viewing 1 out of 5 answers, click here to view all answers.