Topic was automatically imported from the old Question2Answer platform.
Asked By
SF123
I previously requested help with this and got some pretty good ideas, but I need a little bit of help with one of those ideas this time.
I have a variable that is synced across all clients and contains all of the player locations that are not the imposter called, player_locations and I need to loop through those and get the one that is closest to the current player. Then I want to send them a rpc_id(player_id, "killed") call to that player.
I checked your former question, and I guess You are asking for some basic stuff ?
You could take lenghts of vector player.position minus current.position for all players and contain data in array, so You can sort it - from smallest to biggest. Last position in sorted array will belong to player closest to current. Is that the tip You expected ?
The thing I need help with is sorting the list from smallest to largest, I already had an idea of how to get the positions and subtract them.
SF123 | 2021-09-28 22:07
There is a method for sorting array from smallest to biggest, and it is called
sort()
so call it on your array, and get its last element with array[array.size()-1] . You will still need to know which player does this distance belong to, so keep player:distance information in dictionary, so You can compare it woth sorting result later.