2D Top-Down Vehicle Physics

This is a project about modeling some of the forces of land vehicles, in 2D. The mechanisms here are entirely physics-based with an attempt at replicating realistic modeling of weight, torque, friction, air resistance, etc.

Note:

This project was posted twice on the Godot subreddit:

Driving Mechanic

A straightforward algorithm is used without much in the way of optimizations, to focus on understanding the core mechanics.

  • If the vehicle is moving, or has throttle, then iterate over each wheel
  • If the wheel is on the ground, apply its corresponding forces
    • A driving force, if the wheel is powered
    • A braking force, if the brake is applied
    • A perpendicular skidding force
    • A rolling resistance force

Per-wheel driving force is calculated by total_power / number_of_powered_wheels. There is not yet a consideration for transmission mechanics or gear ratios.

The World

The world is built with a few layers of tilemaps, representing the road, walls, overhangs, and shadows. It has a bare-bones aesthetic as the focus of this project was primarily on the vehicle physics.

Special Vehicles

Beyond the various types of cars (normal, nice, sporty) I also experimented with some unique configurations of vehicles.

Motorcycle

A test of the behavior with single-wheel axles.


Truck with Trailer

Adding a hitch mechanic to a vehicle, and a trailer-type vehicle that is un-powered and pulled along.


Large Truck

Testing higher weight and multiple drive axles (the truck has two axles in the rear.)


Armored Car

An experimental vehicle with extra axles and variable turn ratios.


Tank

Testing a track variation of propulsion, that leaves long marks behind it.


Future Work

Improving the Environment Art

The artwork for the vehicles is fun, but the demo environment is lacking.

I'd like to explore ways to make the world look better but I'm unsure exactly what sort of art direction I want to go in. Most top-down games have a bit of tilt (isometric/oblique) instead of being directly top-down like this demo. It seems as though the way forward is to explore an isometric/oblique style for the world and vehicles (which adds some new work), or to experiment with art styles that fit this full perpendicular top-down view.


Modeling Engine/Transmission Behavior

Currently the vehicles all behave like some electric cars, where there is only one gear with a flat acceleration curve.

I would like to be able to model the behavior of different engines and transmissions, with gear changes and proportional speed/torque tradeoffs. However, I need to do a great deal more learning to understand exactly how real cars work.

Game Goals

To make this a game, and not just a demo for this one mechanic, it would need some proper objectives and rewards. Making deliveries, or racing, or causing destruction and mayhem... some sort of task would make this all the more fun.

Vehicle Selection

There is unfortunately no way to change vehicles at runtime (no getting out of a vehicle and into another one.) You have to select your desired vehicle by changing the player variable exported by the test world scene.

The Code

The code for this prototype is on GitHub.

Published: March 28, 2023

Categories: gamedev