using_gridmaps.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .. _doc_using_gridmaps:
  2. Using gridmaps
  3. ~~~~~~~~~~~~~~
  4. Introduction
  5. ------------
  6. :ref:`Gridmaps <class_GridMap>` are a simple and fast way to create 3D
  7. game levels. Think of it as a 3D version of the :ref:`TileMap<doc_using_tilemaps>`
  8. node. Similarly, you start with a predefined library of 3D meshes that
  9. can be put on a grid, just like if you were building a level with an
  10. unlimited amount of Lego blocks.
  11. Collisions can also be added to the meshes, just like you would do with
  12. the tiles of a tilemap.
  13. Creating a MeshLibrary
  14. ----------------------
  15. To begin, you need a :ref:`class_MeshLibrary`, which is a collection
  16. of meshes that can be used in the gridmap. Here are some meshes you can
  17. use to set it up.
  18. .. image:: /img/meshes.png
  19. Open a new scene and create a root node (this is important, as without
  20. the root node, it will not be able to generate the MeshLibrary!). Then,
  21. create a :ref:`class_MeshInstance` node:
  22. .. image:: /img/mesh_meshlib.png
  23. If you don't need to apply physics to the building blocks, that's all
  24. you need to do. In most cases though, you will need your block to
  25. generate collisions, so let's see how to add them.
  26. Collisions
  27. ----------
  28. To assign a :ref:`class_CollisionShape` and :ref:`class_PhysicsBody`
  29. to the meshes, the simplest way is to do it while creating the
  30. MeshLibrary. Alternatively, you can also edit an existing MeshLibrary
  31. from within the GridMap inspector, but only CollisionShapes can be
  32. defined there and not PhysicsBody.
  33. To give the meshes a CollisionShape, you simply add children nodes to
  34. the MeshInstance node. You would typically add the desired PhysicsBody
  35. and CollisionShape in this order:
  36. .. image:: /img/collide_mesh_meshlib.png
  37. You can adjust the order according to your needs.
  38. Exporting the MeshLibrary
  39. -------------------------
  40. To export, go to ``Scene > Convert To.. > MeshLibrary..``, and save it
  41. as a resource.
  42. .. image:: /img/export_meshlib.png
  43. You are now ready to use the GridMap node.
  44. Using the MeshLibrary in a GridMap
  45. ----------------------------------
  46. Create a new scene using any node as root, then add a Gridmap node.
  47. Then, load the MeshLibrary that you just exported.
  48. .. image:: /img/load_meshlib.png
  49. Now, you can build your own level as you see best fit. Use left click
  50. to add tiles and right click to remove them. You can adjust the floor
  51. level when you need to put meshes at specific heights.
  52. .. image:: /img/gridmap.png
  53. As mentioned above, you can also define new CollisionShapes at this
  54. stage by doing the following steps:
  55. .. image:: /img/load_collisionshape.png
  56. There you are!
  57. Reminder
  58. --------
  59. - Be cautious before scaling meshes if you are not using uniform
  60. meshes.
  61. - There are many ways to make use of gridmaps, be creative!