0 votes

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.

Thanks in advance!

Godot version Godot Engine 3.3.3 (Steam)
in Engine by (234 points)

1 Answer

+1 vote
Best answer

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 ?

by (8,097 points)
selected by

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.

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.

Thank you, I will try this.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.