Need tutorial on in game grass editor

Godot Version

4.7.1

Question

I want to make grass that can be edited in game like GitHub - CaptainProton42/2DGrassShaderDemo · GitHub (minus the shaders and wind) but the tutorial is outdated and doesn’t explain everything. Any help or different ways to do this?

The post you have linked is a shader demo. It does not implement gameplay logic. The grass only exists on the GPU.

A TileMap is probably the best path forward. You can make the tile size smaller to make to make the grass appear like pixel art.

How would the tiles take input?

I assume by the cells “taking input”, you mean changing the cell on the TileMap on mouse press?

First, you would need to translate the coordinates of where the player clicks into the cell index. There’s a code snippet on the Godot reference documentation that does this using TileMap.local_to_map.

Next, you would change the cell the player clicked on to using set_cell. See the full scripting reference for TileMap.

You can have different states of grass (e.g. none, short, medium, tall) represented by different tiles.


I looked at the shader code a bit more. There is a live demo the author uploaded.

The shader you linked works by first setting the colour of a texture (as defined in DrawTexture.gd) to between RGB (0,0,0) and RGB (8,0,0). This represents different grass heights, and can be changed by the slider. The shader code then makes this texture look like grass.

To modify this, you would need to basically recreate a lot of TileMap’s functionality to make it easy to interact with in the game world. If you do not understand the demo, then it is probably best to stick with the TileMap.

Thank you so much! I have a nother question can I use if statements to keep moving things (like enemies) on a certain type of tile or do I need to use something else to detect boundaries?

I am not familiar with nav meshes in Godot. There’s a solved thread that talks about using NavPolygons and some considerations. There’s another thread about generating one dynamically.