var collider = interact_ray.get_collider()
if collider is GridMap:
var cell = collider.local_to_map(interact_ray-get_collision_point) var item = collider.get_cell_item(cell)
print(“thats gridmap”,cell, item)
Cell will correctly return the coordinates of the interact_ray but item will only ever return -1.
Idk what I’ve done wrong.
What is the extent to player interaction with gridmap?
Is it possible to select an individual gridmap block in front of the player and interact with it?
For instance, interact with a ‘grass’ gridmap block and turn it into a ‘dirt’ block with player interaction.
Is it possible to use gridmaps for water? Have bouyancy and to fish? I guess this continues from interactions with gridmap.
Is it possible to highlight the block the interact_ray(raycast3d) is currently interacting with so the player can see? Like snapping to the gridmap for a player to place objects in the world?
I’m sorry if these questions get asked often.
Thank you for your help.
The cell item is the item from the MeshLibrary. A MeshLibrary item has no static body, it has only a shape that gets combined later by the GridMap.
Both TileMap and GridMap combine cells to update units, e.g. quadrant size.
So there is never a single cell static body that you can query as if it was a StaticBody node with its own physics body.
If every cell had it’s own physics body you would run a worse version of just using nodes for every cell. Same with visuals, the meshes are rendered with multimesh by quadrant, if you mix meshes for every single cell in a quadrant and also constantly change them you run a worse version of just using meshinstance nodes for every cell.
If you have the collision position you can remap the position to your grid to know which cell has the position. The GridMap has local_to_map() and map_to_local() functions for that or you can just bring the position local to your GridMap and div by cell size to know the xyz of the cell.
It is better to only build your static backdrop with TileMap and Gridmap and all your interactive gameplay elements with normal nodes and shaders on top. You do not have to limit yourself to just one TileMap or GridMap. You can use different maps with just plain cells that you use to mark cells in the editor that you later want to replace with interactables in script when the player comes close.
Both TileMap and GridMap are primarily designed as backdrop placement tools. TileMap is more convoluted with extras because people have twisted it into random directions over the years but still, both are not standalone level builders and definitely not designed and optimized to support “interactivity”. That does not stop many users from still trying. As long as your project scope is very small it might even work but forget doing a large scale game with only TileMap and GridMap with all features like collison and navigation enabled when you need “interactivity”. They are too inefficient with updates for that among other problems.