Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Usando GridMaps¶
Introdução¶
Gridmaps are a tool for creating 3D game levels, similar to the way TileMap works in 2D. You start with a predefined collection of 3D meshes (a MeshLibrary) that can be placed on a grid, as if you were building a level with an unlimited amount of Lego blocks.
Collisions and navigation can also be added to the meshes, just like you would do with the tiles of a tilemap.
Exemplo de projeto¶
To learn how GridMaps work, start by downloading the sample project: gridmap_starter.zip.
Unzip this project and add it to the Project Manager using the "Import" button.
Criando uma MeshLibrary¶
To begin, you need a MeshLibrary, which is a collection of individual meshes that can be used in the gridmap. Open the "mesh_library_source.tscn" scene to see an example of how to set up the mesh library.
As you can see, this scene has a Node3D node as its root, and a number of MeshInstance3D node children.
If you don't need any physics in your scene, then you're done. However, in most cases you'll want to assign collision bodies to the meshes.
Colisões¶
You can manually assign a StaticBody3D and CollisionShape3D to each mesh. Alternatively, you can use the "Mesh" menu to automatically create the collision body based on the mesh data.
Note that a "Convex" collision body will work better for simple meshes. For more complex shapes, select "Create Trimesh Static Body". Once each mesh has a physics body and collision shape assigned, your mesh library is ready to be used.
Materiais¶
Somente materiais no interior das malhas serão usados quando gerado a biblioteca de malhas. Materiais definidos no Nó serão ignorados.
Exportando a MeshLibrary¶
To export the library, click on Scene > Export As... > MeshLibrary..., and save it as a resource.
Você encontra uma MeshLibrary já exportada no projeto chamado "MeshLibrary.tres".
Usando GridMap¶
Cria uma nova cena e adiciona um nó GridMap. Adicione a biblioteca de malhas arrastando o arquivo do recurso do painel de arquivos e soltando-o na propriedade de "Tema" do Inspetor.
The "Cell/Size" property should be set to the size of your meshes. You can leave it at the default value for the demo. Set the "Center Y" property to "Off".
Now you can start designing the level by choosing a tile from the palette and placing it with Left-Click in the editor window. Use Right-click to remove a tile.
Use the arrows next to the "GridMap" menu to change the floor that you are working on.
Click on the "GridMap" menu to see options and shortcuts. For example, pressing S rotates a tile around the y-axis.
Segurando :kbd:`Shift`e arrastando com o botão esquerdo do mouse irá desenhar uma caixa de seleção. Você pode duplicar ou limpar a área selecionada usando as opções do menu.
No menu, você também pode mudar o eixo em que está desenhando, assim como elevar ou abaixar o plano de desenho em seu eixo.
Usando o GridMap no código¶
Veja GridMap para detalhes sobre os métodos do nó e variáveis de membro.