# Physics-based marble race: how can you minimize the gap between first and last?

I'm building a 2D sideview marble game, where they race down the track via gravity. The problem is that once one gets ahead of the others, it usually wins.

In racing games, they can address this by subtly changing the enemies' speed, or the AI's skill, or using power-ups, but I can't do that. I'm looking for obstacles I can add to address this.

The only things I can think of are:

• Gate - holds front players in place until a certain amount catch up, then releases

• Spring - launches marbles up or back, and they have to land just right to continue on the track

Are there any other methods I could use?

• Show some code if possible as it will help people to better answer the question. You really want a way to calculate the distance until the end for each marble. Then you will be able to adjust speed (or any property you like) on the one that is the nearest or furthest from home. For example the Vector2.Distance method might help docs.unity3d.com/ScriptReference/Vector2.Distance.html – I_Keep_Trying Jun 5 at 3:10
• If its a race downwards. You could probably get away with just using the float value for the Y axis (ie. the difference between the home Y position, and the balls current Y position, or even just whichever ball has the lowest Y position value) – I_Keep_Trying Jun 5 at 3:16
• I was hoping for things other than speed adjustment, which I don't think I can do with this system (box2d) – stackers Jun 5 at 3:37
• You could add tar to the track to slow a marble. You can have wind push the slower one to make it temporarily faster or vice versa and have it slow the faster marble. You could make the track crack and cause the marble to slow also. – Justin Jun 5 at 6:06
• Once you know which ball is furthest from the 'goal'. That is what you really need to know. If you know that, then you can speed up the furthest ball, make the nearest one harder to control or slower and lots of other things – I_Keep_Trying Jun 5 at 13:23

## 4 Answers

Add some destructible obstacles (e.g. balloons that get popped, glass that gets broken) that will slow down or even temporarily stop the first player to pass through it, but then is gone and won't affect the rest of the competitors.

The severity of the delay can be based on the current gap between first and last, so the race won't get too lopsided, and a close race won't get tipped the other way.

• I was thinking something similar, like snow on the track that's slow to plow through for the lead marble, but easier for each subsequent marble rolling down the cleared track. – DMGregory Jun 5 at 12:01

For real marbles, the first marble will not accelerate anymore because the force of friction will equal the force of gravity. How can the other marbles make their distance to number one smaller? If they are not accelerating anymore too, how will they ever be able to catch up? If the first marble "makes no mistake", it will surely finish first! A bit boring indeed. So what can we do to let the other marbles approach?

Giving the first marble extra obstacles is indeed possible, but unfair.

Instead, you should give the other marbles the opportunity to close in. You can consider giving them the possibility (though at higher risk!) to take an alternative parallel road, on which friction is less (but the chance of a dangerous encounter with whatever higher), so they can speed up and thereby closing in on the number one.

Included obstacles that have a certain chance per second to be passed. The longer the race goes on, the higher the chance to pass. For example you can have on you track poles that are sinking in the ground. The frequency of emerge is going to be lower the longer the races goes on. Or upwards propeller, with reduced strength later. You can include as gates that open when a certain amount reaches it like a scale that sinks slowly with only one on it but faster the more fall on it.

Add like bowls so like for example the first marble gets second place and second gets first and add some spinners, teleporters, etc. It would be fun and challenging!