I've messed around with pathfinding the past few days, which has resulted in two different demos I'd like to share.
This first one was a test to make intelligent-looking movement with no actual pathfinding whatsoever. Each bot (green hexagon) will patrol and generally attempt to guard the map's beacons (blue/white triangles). Beacons which are outlined (instead of filled) are "walk" beacons, which encourage a bot to keep moving to other beacons. Bots have a few different kinds of behaviors, which are randomly set at map generation. Red lines are walls which may not be passed.
The second test is a little less interesting to me, but may be a bit more useful. Quite simply, it has the bots pathing along the beacons towards a goal beacon (outlined in green) using a standard A* algorithm with a pretty efficient implementation. Not too special, in my humble opinion.
The controls are largely the same for both tests: Press R to disable the automatic map switching, and press R again to re-enable it and generate a new map. Left-click will add beacons (hold Alt for walk-beacons in the first test), Right-click will remove them (Middle-click will specify the goal in the second test). Ctrl- Left- and Right-click to add/remove bots. Holding Shift lets you mess with the walls - Left-click will add new ones, Right-click will remove them, and Middle-dragging lets you move their endpoints.
When modifying the map, changes are instantly worked with in the first demo. In the second, you need to press E to start generating new paths for the bots. Also of note is how I used coroutines to ensure smooth framerate during heavy computations (especially those of the A* demo).
So, comments and critique? Should I abstract my A* implementation and turn it into a pathfinding module for Love? Would anyone use it?
Two studies in pathing
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Two studies in pathing
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Two studies in pathing
I'd be interested in using it. Why not use LÖVE's threads instead of coroutines?
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Two studies in pathing
Because Love's threading support appeared to be seriously broken. I didn't know until just a few minutes ago that it was fixed in 0.7.1. But also because threads don't share variables, and it would take a lot of work to keep the beacons synchronized on both sides at once. Coroutines, on the other hand, share variables.
The A* version seems more suited to threads than the original, though. Maybe it would be worthwhile for static maps.
EDIT) Well, this turned into that. Good stuff.
The A* version seems more suited to threads than the original, though. Maybe it would be worthwhile for static maps.
EDIT) Well, this turned into that. Good stuff.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Who is online
Users browsing this forum: No registered users and 1 guest