In my game players can destroy the terrain and often as it is blown up randomly, small levitating parts of the terrain can remain here and there.
Like seen here: a small terrain part remained in the air with a coin on top of it:
How should I write a script that would periodically find these (standalone, small terrain parts) and give the approximate center Position.
With the Position I could use that to get rid of them no problem, just have no idea how to look through the terrain matrix/points or whatever to find these.
Is this possible?
I’m a level designer.
Please help me if you have any suggestion what I should try.
Thanks!
You can define one part of the terrain in a script as “anchored”. If there is a possible path from one piece of terrain to an anchored piece, it should not fall. If not, it should fall. Whenever a player removes a piece of terrain, you should check only the surrounding pieces of terrain to the one removed, if there are more than one group of touching pieces, the player has made a cut in the terrain in some way and you need to do the above check, otherwise you don’t need to.
Most pathfinding algorithms, like A*, are “greedy” which means given a big volume of terrain it will quickly cross it to the destination point without spreading out, so it should perform acceptably fast.