[MPGAME] Mad Mobiles (a working name)

One idea I had for the collision is to use a 256-color palette but use the upper 2 bits of the index as the collision mask (normal road, wall, rough terrain, slippery terrain). Then instead of masking the upper bits out of the index during the render phase you can actually take advantage of 64 unique colors for normal road terrain, 64 for wall textures, 64 for rough terrain, and 64 for slippery terrain. Alternatively, but similarly, you could split the 256-color palette into regions (with occasional duplicate colors) where all normal road tiles use colors from region 0, walls only use colors from region 1, etc, etc, as long as the total colors from each region add up to 256. The latter approach would also allow more than 4 regions without complicating the code too much as it’s still just an if (index < REGION0_START) {/*normal road*/} else if (index < REGION1_START) {/*walls*/} etc.

1 Like

Now I start to understand how SDF works. This is the best explanation of SDF I could find:
https://renderdiagrams.org/2017/12/28/signed-distance-fields/

On the other note: modeling the car physics is not easy. Even in 2D. It would be much easier to model a spaceship movement when the is no tyres, friction or air pressure.
Because of tyres the car behaves differently at higher speeds when tyres start to lose grip.

Simplest solutuion I can think of is ignore sir pressure. For friction define a curve (linear or bezier) for speed 0 to max speed (this can optionally vary by car). Then when turning determine grip using this friction. The grip should be give you 3 values summing to 1.0. One value is the forward change in speed as the car turns, one for the laterall change in speed, and finally one for the loss. Sudden breaking would decrease the grip factor causing you to slide or drift. This also makes it possible to modify the grip based on the ground material. You’ll have to play around with the values a bit to find the right balance but that shouldn’t be too hard.

1 Like

The average gfx update speed in the online play of 5 players with an SDF rendered track was 29 fps with “-O3” -option on HW build, which is very good! Still, the size of the Pokitto binary was 156 kb, as with tile-based track it was about 190 kb.

So SDF is definedly the way to go :smiley:

Sorry, I did not understand your car physics model. Care to elaborate? Also a picture might make it clearer.

I think that the physics model is now good enough so I will start implementing collision. First a collision to the track edge and then to other players.

1 Like

Ok, collision to track edges is working! :smiley:

For some reason, the clients go out of sync after some time. Yes, there are complex collision checks but all are fixed point math and all the timings are based on the frame counter so it should be deterministic. :thinking: Interesting!

1 Like

Found it! :smiley:

It was a animation that I first thought was not affecting to the game state. The car animation frame was given differently in the local and remote instance of the same car. It affects to the car position as I have given each frame also an offset in pixels. So the animation frame affected to the car position and therefore also to the collision calculation ==> non-deterministic

2 Likes

Autonymous driving :grin:
There is not yet car-to-car collisions.

4 Likes

This is looking really awesome. I would hope cars could go off into the grass and just get slowed down, but then you would need to setup some kind of invisible waypoint system to prevent abusive shortcuts, but you’ll most likely need to implement a basic system anyway to prevent going backwards over the finish line then turning around and crossing the finish line.

Thanks!
Yes, there needs to be a system to prevent shortcuts and going backwards.

In the collision check, you could add a grass strip between the track and the wall. Instead of just checking if distance is smaller than the given limit (car bounding circle radius r), you could do something like this:

if distance < -grass_width + r:
  // Wall, handle collision
else if distance < r:
  // Grass, slow down, no collision
else:
  // Asphalt

There would still be the wall to prevent shortcuts, but you wouldn’t crash into wall immediately if you go off asphalt.

1 Like

Now the car-to-car collisions are working!

TODO before the MP test session:

  • Givesome immediate response when the thrust is pressed
  • The SDF track should have some extra space in the top and left edges of the map
  • Make a checkpoint so that the reverse direction driving is not possible
  • Make the finishing line gfx
  • Detect crossing the finishing line and select the winner!
  • audio(?)
5 Likes

This is definitely looking really awesome. Can’t wait for it to be ready for a test session.

2 Likes

An update!

  • @jpfli optimized the line filler so that textures can be used instead of solid colors :smiley: Also he added different terrain types: if you go on sand your speed will be slowed down. He also improved collision physics.
  • I added a finishing line and now the cars are gathering behind that on start.
1 Like

looks good !! do you think we can have a test session about it soon? :grin:

That is not too far away now! Just need to make the game to know the winner and make it able to restart the race. Plus a couple of smaller tweaks and that’s it :slight_smile:

1 Like

It took some to make the “race results” list as I wanted that the player can see the other cars finishing the race as well. Also having a lot of text and graphics at the same time is not good in TAS mode as there are limited number of elements on screen.

So I used the scrolling list at the top of the screen for results.

4 Likes

This just keeps looking better and better. Can’t wait to see what more you’re able to squeeze into it.

2 Likes

Just the final test still and then I can start to schedule the test session… :smiley:

3 Likes