This project simulates a 2D soft body car inspired by Jelly Car using Python and Pygame.
The simulation is physically driven using PBD.
There are two kinds of constraints implemented: Pin constraints and Spring constraints.
There are three kinds of collisions implemented: Particle with Rectangles, Polygons, and Soft Bodies
The car consists of a rectangular chassis and 2 wheels, which are soft bodies.
The wheels are connected to the chassis using pin constraints.
There lots of springs between the particles of the soft bodies to ensure that
when they are squished, even flattened, they will return to their original shape.
There are 2 necessary mechanics to make the car move:
When the left or right arrow keys are pressed, a force is applied to all of the edge particles on the wheels in the direction of the wheel's rotation. This causes the wheel soft body to spin, but the car would not move if it were not for the friction with the ground. The friction is implemented as Coulomb friction and is applied to particles whenever they collide with something. I added some extra features to the simulation for more interesting levels:
Three different scenes are available in the simulation:
Click the play button to start the simulation. Use the arrow keys to control the car.
The comma and period keys can be used to zoom in and out, respectively.
You can set the scene by changing the scene
variable at the top of the main code.
If you really want to, you can modify the scenes as you please. The existing scenes show how to create objects of
each type.
The performance of the simulation is very poor in the browser. Also, I'm not sure how long the Trinket embed will last, so it is recommended to run the code locally for a better experience. The only requirements are Python and Pygame.
Here is a short presentation of the simulation.