Swap meshes in front of player with another mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CodeGuru12

I’ve been trying to solve this issue for a few days now. I’m working on a farming simulator, and trying to prototype hoeing grass into dirt for planting.

I found this from one of Godot’s tutorials: Spawning monsters — Godot Engine (latest) documentation in English

But this does something using a specific scene, which would limit me later. (Not sure how to get around it)

I also found this, but the example is incomplete: Spawning monsters — Godot Engine (latest) documentation in English

So far I’ve tried to use a GridMap with set_cell_item. But I can’t get the location right, and I can’t seem to remove the object currently in place of the swapped object. (I’ve also heard the GridMap solution doesn’t scale very well).

In any case, any help would be greatly appreciated.

:bust_in_silhouette: Reply From: Inces

With an idea like this GridMap is still best sollution. Too bad in Godot 3.1 it is kind of clunky.
What do You mean You can’t get position right ? You propably need to dig into how world_to_map and map_to_world work, it is easy.

Set_cell_item should remove former item. If it is not happening, than You must have messed up tile scale. Simply set cell_size to be the very same as size of meshes ( in meters actually, just change it until one mesh fits in one cell ).

Never change scale of whole GridMap node.

Remember, that if You want to place some objects onto another ( like fence on the grass ), than You will need two gridmaps