AI disclosure: The code for this mod was written with an AI assistant (Claude), directed and tested by me.
This mod ports the Box2d source files into The Powder Toy to allow for rigid body simulation. The all the integrations between Box2d and TPT are written by AI.
The Rigid Body Mod adds exactly what the title says, rigid bodies. Draw a box of RIGD and it falls, lands, tips over edges, slides down slopes, stacks and rolls, keeping its shape. Bodies float or sink in liquids by density, push liquid aside, and hollow shapes trap air and float like boats.
New elements (in the Solids menu)
- RIGD, iron: sinks in water, floats on mercury, conducts
- RWOD, wood: floats on water and oil, burns
- RRBR, rubber: very bouncy and grippy
- RICE, ice: almost frictionless, floats in water, melts above 0°C
- RSTN, stone: sinks in water, floats on lava and mercury
- RFOM, foam: rides high on any liquid, burns
- RGLD, gold: sinks even in mercury, conducts
For performance reasons single pixels are treated like normal powder. Molten rigid materials behave like other molten materials and are not rigid bodies. When cooled, they reform as a rigid body again. There is an option in Simulation Options to allow liquids to even out around floating bodies.
Known limitations
- Powders act as solid ground. Rigid bodies will rest on any non-liquid powder rather than sinking in.
- Body velocities aren't saved and start at rest after loading.
- A rigid body packed tightly inside another body can lag slightly behind it while both are moving.
- Rigid bodies are not affected by pressure or air currents.
Download: https://github.com/Zivodor/TPT-Rigid-Body-Mod/releases/tag/v0.0.1
Source code: https://github.com/Zivodor/TPT-Rigid-Body-Mod (branch rigid-bodies, tag v0.0.1)
Credits: Built on The Powder Toy by its developers and contributors. Rigid body physics by Box2D, Copyright (c) 2022 Erin Catto, MIT license (https://box2d.org).
This is my first time posting, if I am in the wrong place, need to include more details, or am missing something. This was like a half day of vibe coding, it's fairly performant from my own testing, but no promises. I'm not a C++ dev so code is implemented as is by the agent.
I just wanted the play with rigid bodies. Lua scripts would be way way too slow. I'm pretty sure the only reason this can run with any amount of performance is that its compiled and box2d is performant. Also no, I won't be rewriting anything. I'm not a C++ dev. If anyone wants to de-ai it you have my blessing. I just wanted to play with rigid bodies in TPT.