In Castronauts, the mattress sinks under a player's feet and slowly rises when they jump away. The team shares how they made it in Godot.
Moon Egg Studios saw clips of a ball sinking into a 3D pillow and decided to try the idea in 2D. In
Castronauts, their co-op game about catching alien fish on dangerous planets, the crew can land on a mattress that gives way beneath them.
The team made a custom node called SoftCushion in Godot 4.6. It treats the 30 × 8 pixel mattress as a row of springs placed at the edges of its pixel columns. Each spring moves only up or down.
When a player lands, the columns beneath them sink. They stand on an invisible, one-way platform that lowers with the springs, so their feet sink too. Once they jump away, the compressed columns slowly return to their original shape.
Once a column compresses more than 1.4 pixels, a U-shaped outline appears around the dent. The outline takes its color from the bottom pixel of each column, tucked behind the bedframe so the pillow and blanket can keep their own colors.
Furniture in Castronauts is normally drawn behind the characters, so the mattress cannot hide their feet on its own. SoftCushion draws a second copy in front of the player while they stand on it. Their platform sinks 3 pixels for a 2-pixel dent, letting that copy cover the bottom row of their feet. It disappears when they jump off.
The springs only update while the mattress is pressed or returning to shape. Once they settle, SoftCushion checks player positions. When the crew is away exploring planets, it stops running.
In co-op, each player's game runs SoftCushion locally, so the effect needs no extra network packets.
You can follow Castronauts and Moon Egg Studios here:
We just released our new
Godot All About VFX Bundle, it covers shaders, particles, and VFX for 2D, UI, and 3D games with step-by-step examples in over 600 pages of content! ✨