2D Vehicle Physics in Solar2D

Last year, back during development of Another Tomorrow, my daughter saw one of the puzzles we were working on and fell in love.

In this puzzle you control a little RC car, from above, by tapping where you want it to drive. The rub is that you’re in a temple and some of the slabs of the path are booby-trapped so will collapse when you drive on them.

She called this the “up down” game and would continuously come into my office to ask if she could play it.

Lily attempting to drive with her eyes covered.

Two games, and a house move, later I am now going to attempt to make her a little car game that she can mess about with.

However now that she’s mastered tapping to drive I thought it was time to move onto ‘real’ driving and so went on the hunt for vehicle handling for Solar2D, the engine that I use, and came up empty ( admittedly I didn’t search for long so there is a strong chance it already exists ).

So my next step was to find someone else’s work and see if I could port it over, and that led me to Marco Monster’s paper on car physics.

I am fully willing to admit that this went completely over my head and so I kept searching and found a car physics library by SpaceJacks that is based on it.

Thankfully it was fairly trivial, even for me, to port the javascript code to Lua so here it is in all its Lua glory.

I also made a very simple demo which can be downloaded from here as well as played below.

It’s pretty rudimentary but you can steer with left/right, accelerate with up and brake with down. Plus space for a handbrake.

Showing this to Lily she’s already chuffed however I think it might need a little more to really be considered a game, but if nothing else she’s happy so I’m happy.

There are a fair number of settings you can change to feel of your vehicles just right, and in the next post I’ll be talking about a simple camera for the currently-unnamed driving game.

2 Comments 2D Vehicle Physics in Solar2D

  1. Pingback: 2D Camera for Solar2D – Graham Ranson

  2. Pingback: Driver AI in Solar2D – Graham Ranson

Leave a Reply

Your email address will not be published. Required fields are marked *