Files
godot-demo-projects/3d/voxel
Hugo Locurcio a531235db3 Use Jolt Physics in all 3D demos that use physics, improve physics tests demos (#1195)
- Add options for physics ticks per second, time scale, max physics steps per frame
  and physics interpolation to the 2D and 3D physics tests demos.
  - Physics ticks per second are always multiplied by time scale so that
    time scale does not affect the physics simulation quality.
- Enable 4× MSAA for better debug shape display. Remove meshes/lights as
  the debug collision fill make these unnecessary.
  - Switch to the Mobile rendering method in the 2D physics tests demo
    to allow for 2D MSAA, as it's not implemented in Compatibility yet.
- Improve collision shapes color in the 2D and 3D physics tests demos
  for better visibility. Each PhysicsBody type now has its own collision
  shape color.
2025-04-21 21:59:31 +02:00
..
2025-03-21 02:00:41 +01:00

Voxel Game

This demo is a minimal first-person voxel game, inspired by others such as Minecraft.

Language: GDScript

Renderer: Forward+

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2755

How does it work?

Each chunk is a StaticBody3D with each block having its own CollisionShape for collisions. The meshes are created using SurfaceTool which allows specifying vertices, triangles, and UV coordinates for constructing a mesh.

The chunks and chunk data are stored in Dictionary objects. New chunks have their meshes drawn in separate Threads, but generating the collisions is done in the main thread, since Godot does not support changing physics objects in a separate thread. There are two terrain types, random blocks and flat grass. A more complex terrain generator is out-of-scope for this demo project.

The player can place and break blocks using the RayCast node attached to the camera. It uses the collision information to figure out the block position and change the block data. You can switch the active block using the brackets or with the middle mouse button.

There is a settings menu for render distance and toggling the fog. Settings are stored inside of an AutoLoad singleton called "Settings". This class will automatically save settings, and load them when the game opens, by using the File class.

Sticking to GDScript and the built-in Godot tools, as this demo does, is quite limiting. If you are making your own voxel game, you should probably use Zylann's voxel module instead: https://github.com/Zylann/godot_voxel

Screenshots

Screenshot

Screenshot

Licenses

Textures are from Minetest Game.

Some textures Copyright © 2010-2018 Minetest contributors, CC BY-SA 3.0 Unported (Attribution-ShareAlike) http://creativecommons.org/licenses/by-sa/3.0/

Some textures Copyright © 2010-2018 Minetest contributors, CC0 1.0 "No rights reserved" https://creativecommons.org/publicdomain/zero/1.0/

Font is "TinyUnicode" by DuffsDevice. Copyright © DuffsDevice, CC-BY (Attribution) http://www.pentacom.jp/pentacom/bitfontmaker2/gallery/?id=468

While most textures are under CC BY-SA 3.0, some are under CC0 1.0

Cisoun's texture pack (CC BY-SA 3.0):

  • default_stone.png
  • default_leaves.png
  • default_leaves_simple.png
  • default_tree.png
  • default_tree_top.png

celeron55, Perttu Ahola celeron55@gmail.com (CC BY-SA 3.0)

  • default_mineral_iron.png
  • default_mineral_coal.png
  • default_bookshelf.png

VanessaE (CC BY-SA 3.0):

  • default_sand.png

Calinou (CC BY-SA 3.0):

  • default_brick.png

PilzAdam (CC BY-SA 3.0):

  • default_mineral_gold.png

jojoa1997 (CC BY-SA 3.0):

  • default_obsidian.png

InfinityProject (CC BY-SA 3.0):

  • default_mineral_diamond.png

Zeg9 (CC BY-SA 3.0):

  • default_coal_block.png

paramat (CC BY-SA 3.0):

  • default_bush_stem.png
  • default_grass_side.png -- Derived from a texture by TumeniNodes (CC-BY-SA 3.0)
  • default_mese_block.png

TumeniNodes (CC BY-SA 3.0):

  • default_grass.png

Blockmen (CC BY-SA 3.0):

  • default_wood.png

sofar (CC0 1.0):

  • default_gravel.png -- Derived from Gambit's PixelBOX texture pack light gravel

Neuromancer (CC BY-SA 3.0):

  • default_furnace_bottom.png
  • default_furnace_side.png
  • default_cobble.png, based on texture by Brane praefect
  • default_mossycobble.png, based on texture by Brane praefect

Gambit (CC BY-SA 3.0):

  • default_diamond_block.png

kilbith (CC BY-SA 3.0):

  • default_steel_block.png
  • default_gold_block.png
  • default_mineral_tin.png

Mossmanikin (CC BY-SA 3.0):

  • default_fern_3.png

random-geek (CC BY-SA 3.0):

  • default_dirt.png -- Derived from a texture by Neuromancer (CC BY-SA 3.0)

Krock (CC0 1.0):

  • default_glass.png