Hello all,
I am making a simulation of a pathfinding robot for a project I am working on - there are three maps in the simulation, the first is the "real" map, containing all obstacles and a target; the second is the "internal" map, which starts off empty but is filled as the robot detects obstacles as it moves towards its target (the detection process is simply scanning an area around the robot and adding any tiles in the area to the other map); and the final is a simplified node map with nodes connecting all separate areas with lines illustrating paths between them.
The problem I've run into is that I just can't work out how to detect separated areas - I would like the robot to detect empty areas and use their center points as the nodes for the simplified node map. An illustration of what I am trying to achieve:
Thanks in advance.
-Gopiandcoshow
I have included my project .love file - no pathfinding is currently implemented, only the detection - the robot can be manually controlled with the arrow keys and the internal map can be seen by holding "a".
Detection of connected areas in a map
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Thu Mar 12, 2015 5:02 am
Detection of connected areas in a map
- Attachments
-
- Prototype.love
- (49.22 KiB) Downloaded 52 times
Re: Detection of connected areas in a map
Detecting connected areas is usually done using a floodfill algorithm. To make this work for you, the individual areas need to be clearly separated. Otherwise, they count as one large area. To get them separated, you can try to increase the boxes (virtually) until they touch. Or you could iterate over all boxes and if two boxes are closer than 2 tiles, then draw a connection between them.
However, I think you don't need this separation at all. Is there any reason, why you want to avoid path finding on the full grid?
However, I think you don't need this separation at all. Is there any reason, why you want to avoid path finding on the full grid?
Check out my blog on gamedev
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests