How to program action game in a wrapping world? (2D torus)
Posted: Sat Jan 01, 2022 12:51 pm
Imagine simple top-down arena shooter, bump.lua for collision, tile map made in Tiled or proceduraly generated, standard stuff except the edges of the map are connected, kind of like in Asteroids.
This game seems to have implemented it pretty well https://benjamin-soul.itch.io/voidrun, look at the second .gif, notice that singular ground tile sticking out of water in one of the pools, you can see it at the bottom first, then when player goes north you can see it at the top, the world loops seamlessly. How would you implement this in game? I've searched through reddit posts, forums and articles but couldn't find any solution, everyone suggest the same naive implementation that only works in something very simple like Asteroids, as in: when object goes out of map bounds, teleport it to the other side, they also suggest drawing everything 4 or even 9 times to make it visible through the "loop" when near the edge of the map, also checking collisions extra 4 times to account for all the wrapping directions, well, you can probably see how it's not going to work well, all the edge cases you have to individually code for etc etc.
Here's one example, illustrated
Green is floor, light blue is impassable water, grey is mountains (obstructs enemy vision). Yellow is player with their camera viewport selected, since the map wraps around they should be able to see the white square. Red and orange don't have a clear line of sight for each other if you compute it normally since the mountain blocks it but they should be able to see each other, looking the other way through the edge of the map. Red and orange also see the player, they can't pathfind to player if it was a normal map with impassable edges but since it loops they should be able to reach player by going south.
I feel like there is some way to program a system that elegantly and automatically handles all this but I just can't figure out how to do it, I have played Voidrun, kept running in one direction, looping around the world and the enemies perfectly follow and shoot at me, there are no obvious gaps or connected edges while playing, it's seamless.
https://twitter.com/benjamin_soule_/sta ... 0998666241
https://twitter.com/benjamin_soule_/sta ... 5538442240
https://twitter.com/benjamin_soule_/sta ... 9649017861
Even those segmented worm enemies work perfectly, no way you could get it to work cleanly with the hacky "drawing everything multiple times and checking collisions multiple times in all directions" method since that doesn't cover pathfinding, line of sight, aiming and shooting etc. How?
This game seems to have implemented it pretty well https://benjamin-soul.itch.io/voidrun, look at the second .gif, notice that singular ground tile sticking out of water in one of the pools, you can see it at the bottom first, then when player goes north you can see it at the top, the world loops seamlessly. How would you implement this in game? I've searched through reddit posts, forums and articles but couldn't find any solution, everyone suggest the same naive implementation that only works in something very simple like Asteroids, as in: when object goes out of map bounds, teleport it to the other side, they also suggest drawing everything 4 or even 9 times to make it visible through the "loop" when near the edge of the map, also checking collisions extra 4 times to account for all the wrapping directions, well, you can probably see how it's not going to work well, all the edge cases you have to individually code for etc etc.
Here's one example, illustrated
Green is floor, light blue is impassable water, grey is mountains (obstructs enemy vision). Yellow is player with their camera viewport selected, since the map wraps around they should be able to see the white square. Red and orange don't have a clear line of sight for each other if you compute it normally since the mountain blocks it but they should be able to see each other, looking the other way through the edge of the map. Red and orange also see the player, they can't pathfind to player if it was a normal map with impassable edges but since it loops they should be able to reach player by going south.
I feel like there is some way to program a system that elegantly and automatically handles all this but I just can't figure out how to do it, I have played Voidrun, kept running in one direction, looping around the world and the enemies perfectly follow and shoot at me, there are no obvious gaps or connected edges while playing, it's seamless.
https://twitter.com/benjamin_soule_/sta ... 0998666241
https://twitter.com/benjamin_soule_/sta ... 5538442240
https://twitter.com/benjamin_soule_/sta ... 9649017861
Even those segmented worm enemies work perfectly, no way you could get it to work cleanly with the hacky "drawing everything multiple times and checking collisions multiple times in all directions" method since that doesn't cover pathfinding, line of sight, aiming and shooting etc. How?