Coroutines are awesome
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Coroutines are awesome
I will give a shiny Stanley Nickel to the first person who converts LuaStar to use Coroutines so I can have my characters think about their paths without pausing the execution of the game for half a second.
Re: Coroutines are awesome
Here's my personal implementation of A*: https://github.com/inmatarian/landofway ... finder.luaJasoco wrote:I will give a shiny Stanley Nickel to the first person who converts LuaStar to use Coroutines so I can have my characters think about their paths without pausing the execution of the game for half a second.
Of course, it'll undergo massive tweaking as I work on this project. Anyway, line 99 is the code you're interested in.
Here's a mob that uses it: https://github.com/inmatarian/landofway ... nenemy.lua
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Coroutines are awesome
Thanks! After a bit of work I have something working.
I am a bit surprised though. I notice your path is returned as a string of directions. N, S, E, W instead of a table of X and Y values. Any reason for this? Not that it matters. This actually could work in my favor. Haven't decided whether I'll convert it to an X, Y table version or keep the directions. I do need to do more testing to see how it holds up and if there's any delay while running my game with a dozen enemies all making decisions at once.
I am a bit surprised though. I notice your path is returned as a string of directions. N, S, E, W instead of a table of X and Y values. Any reason for this? Not that it matters. This actually could work in my favor. Haven't decided whether I'll convert it to an X, Y table version or keep the directions. I do need to do more testing to see how it holds up and if there's any delay while running my game with a dozen enemies all making decisions at once.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Coroutines are awesome
Having some success, but also encountering a really strange bug where my enemy object will stop halfway through following its path. It's very strange. I had one where I made 100 enemies and 90 of them stopped and refused to move. Is there a limit to how many coroutines can be running? Am I jamming this too full?
I can't see why though since they freeze after they've already generated the path and have started following it. So weird.
Bottom line is I haven't had any slowdown while all of them choose paths. But my grid is only 21x14 tiles. I'll have to test it out with a grid much larger.
I can't see why though since they freeze after they've already generated the path and have started following it. So weird.
Bottom line is I haven't had any slowdown while all of them choose paths. But my grid is only 21x14 tiles. I'll have to test it out with a grid much larger.
Re: Coroutines are awesome
The underlying objects move on a fixed grid. I came from the ZZT/MZX background (I was inmate2993) and the project is heavily influenced by it, so NSWE directions are how I designed everything. The A* engine was built in the same mindset.
I'm not sure what your bug is, but if you pulled code from the DragonEnemy, he's cutting down the path to a part of itself. Since the player is actively moving, the enemy is only using A* to get around obstacles and return to attacking, not to touch the player. In fact, one of the places I need to upgrade the A* is to allow a good enough path when it can't find the best path.
A simpler demonstration of my A* engine is this sprite: https://github.com/inmatarian/landofway ... rhardt.lua
On line 24, he gets the path and then immediately follows it.
I'm not sure what your bug is, but if you pulled code from the DragonEnemy, he's cutting down the path to a part of itself. Since the player is actively moving, the enemy is only using A* to get around obstacles and return to attacking, not to touch the player. In fact, one of the places I need to upgrade the A* is to allow a good enough path when it can't find the best path.
A simpler demonstration of my A* engine is this sprite: https://github.com/inmatarian/landofway ... rhardt.lua
On line 24, he gets the path and then immediately follows it.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Coroutines are awesome
Still working on bug shooting but I modified the pathfinder so instead of returning the path, it applies the path to the enemy object from within itself immediately after it builds the table of directions. I know that's not the problem because I made it work this way after having the problem to try and fix it. I'll figure it out. It's weird and probably a silly oversight on my end. I doubt it's the pathfinding since they usually freeze halfway through following a path. So it's probably a bug in my own following code. Weird though because even if I have only 2 enemy objects, eventually one of them gets stuck while the other never seems to. Need to do more analyzing.
Edit: Well I'm silly. I wasn't even creating a coroutine to put the pathfinding function in. Not that that has anything to do with my problem. It just proves the bug has nothing to do with coroutines. lololol
Edit: Well I'm silly. I wasn't even creating a coroutine to put the pathfinding function in. Not that that has anything to do with my problem. It just proves the bug has nothing to do with coroutines. lololol
Re: Coroutines are awesome
btw, this should beJasoco wrote: ↑Thu Mar 22, 2012 4:03 amCode: Select all
function love.update(dt) coroutine.yield(co) end
Code: Select all
function love.update(dt)
coroutine.resume(co)
end
Re: Coroutines are awesome
10 years later...
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
- Gunroar:Cannon()
- Party member
- Posts: 1139
- Joined: Thu Dec 10, 2020 1:57 am
Re: Coroutines are awesome
Ahhh, now I understand the foolishness of necro-ing.
Edit: But at least it clears confusion for anyone seeing the thread now
Edit: But at least it clears confusion for anyone seeing the thread now
Last edited by Gunroar:Cannon() on Sun Sep 18, 2022 9:10 pm, edited 1 time in total.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests