#Gravity for tilemaps (C#)

1 messages · Page 1 of 1 (latest)

thorny plaza
#

I'm trying to make floating blocks disappear (that aren't the grey ground tile) ```private void FloatingTileUpdater()
{
var cells = GetUsedCells(0);

foreach (var cell in cells)
{
    bool cellIsFloating = true;

    var surroundingCells = GetSurroundingCells(cell);
    var cellAtlas = GetCellAtlasCoords(0, cell);

    foreach (var surCell in surroundingCells)
    {
        var surCellAtlas = GetCellAtlasCoords(0, surCell);

        if (surCellAtlas != new Vector2I(-1, -1) || cellAtlas == new Vector2I(2, 0))
        {
            cellIsFloating = false;
            break;
        }
    }

    if (cellIsFloating)
    {
        EraseCell(0, cell);
    }
}

}```

Currently, a single tile will disappear when floating and I understand that two floating blocks checking eachother that one another are there will mean that they won't disappear but I can't think of how to make it otherwise, any advice? Thanks!

fading ridge
#

Why not check below only?

thorny plaza
#

because it means if I had structure that was like an upside down L or T or something then the side bits would disappear and I don't want that, unless I'm being really stupid and overcomplicating this

#

I would basically have to check every single block in the structure to see if it's floating and it feels like there's a smarter way

fading ridge
#

Ah, you might want to look at path finding then. A-star grid based mainly. If you find a path: connected to flor, if not: floating.
https://kidscancode.org/godot_recipes/4.x/2d/grid_pathfinding/index.html
https://www.youtube.com/watch?v=EPkaQFyEGQg

Thanks for watching my video!

Here is the Github link for the script: https://github.com/uheartbeast/astar-tilemap

If you are interested in taking a deeper dive into the Godot game engine you can buy my 1-bit Godot Course at this link: https://www.heartgamedev.com/1-bit-godot-course-youtube

Check out my Patreon: https://www.patreon.com/uheart...

▶ Play video