New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query functions ordered by distance #5
Comments
actually, I guess did this for my old project. I was searching for nearest enemy(or hero) in attack range on turn based game. It was a draft quality project but I'm going to try to find the code that I did. It might be useful. |
I believe the only struggle here would be to extract the positions for given ids from the dynamic tree to calculate those distances, right? ;) |
Nope, this is the easiest part. It is possible to extract their center position and distance from given id. I already have those math functions. Most challenging part is the ordering the array by distance with ids. :) Unfortunately it is not simple as lua with C. |
Hi @8bitskull Distance based shorting is on dev branch now. Please use this url as dependency: I'm going to clean up the code if works for you. I just did a few small sized tests but it is hard for me to test it on large scales as your game require. I prefer to use separate functions since I don't want to implement an extra if-else check on the exist functions. Params are same. It is enough to add
I made a change on returning results. Now, they are returning IDs and Distances. This might cause you a lot of extra work. { --[[0x10e32b530]]
1 = { --[[0x10e32b590]]
id = 3,
distance = 0
},
2 = { --[[0x10e32b630]]
id = 0,
distance = 39
}
} Also I updated the example(it is the same but just in case) I hope this cause a performance gain... |
Thanks very much @selimanac. I can confirm that it works as expected. It reduces my targeting function from 24 lines to 9 lines and produces much more robust results - before, my function was guessing the closest enemy within an error margin to save on performance. Now I get the actual closest enemy. |
@8bitskull I made a typo on function names. All |
Would love to have either separate functions or a function option that returns hits ordered by distance.
Use case for example would be a unit seeking to target an enemy. It gets a list of enemies within its range using daabbcc.query(), and saves the first instance as a target because the table is ordered by distance.
The text was updated successfully, but these errors were encountered: