2
\$\begingroup\$

I am looking to add a feature to my mobile game (IOS and Android) to let users connect to trade with users nearby in a certain radius based on the real world geolocation. Whats the best approach to find nearby users who are also running the game right now?

I have looked into using bluetooth using assets such as this: https://forum.unity.com/threads/android-bluetooth-multiplayer.188667/ but it seems like there is nothing for bluetooth multiplayer between android and IOS.

There is plenty of AR tools like this one: https://cloud.google.com/maps-platform/gaming however non seem to have the feature I am looking for.

Or perhaps if there is no existing solution for this. I have to share and compare player locations via a game server. However I have no idea what my first steps would be for that.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Combined Geolocation and game server processing

Each device (with appropriate permissions) may report its location to the server. This can be done using LocationService

You'll want to update location semi-regularly.

You can then answer polls from the device for a list of nearby players. Be sure to either anonymise or outright hide anything they don't need to know in the request. Just send a list of user-IDs and other information relevant to the trade.

Your server simply scans through its list of active players (most likely generated by looking for users that have sent their locations in the past minute or two) and compares the location data by latitude/longitude to a given decimal precision. If they match, they're in the same area and can trade. Some trial and error may be required to decide what level of precision is needed.

This spits out a list of nearby players, probably only a few at a time, and sends that back to the player who requested it.

The rest is a matter of handling trade-requests.

This is something I've actually done for a game in the past (sadly that game is no longer available).

Our system essentially treated the Trade as a series of communications around a server-side data-class.
* User A tells the server they want to trade with User B.
* The server creates a trade object, assigns the creator as User A, then pings User B with the trade-request.
* If they say yes, they're added as the second party in the trade, if no, the trade object is deleted and User A is notified that they refused.
* Once they're both in place, they can both see the Trade Object in their UI, items can be added or removed from their respective tables, and they can submit that they're happy with it.
* Once they've both agreed, the trade is performed, the items are swapped by the server, notifications are sent and the trade is marked as completed which prevents further interaction.

All of the interactions with the Trade object are handled as server requests, no information is directly sent between users at all at any stage for security reasons. The whole thing must be arbitrated by the server.

The paradigm is that users may only ever read data and make requests to change it, they cannot change the data directly.

\$\endgroup\$
2
  • \$\begingroup\$ Things to watch for with this: 1) You'll want to use a spatial partition to narrow your search of nearby users, so you don't have to check every active user. 2) Beware that 1° of longitude is a different distance near the equator than it is closer to the poles — if you use latitude & longitude, compensate your search ranges/bucketing accordingly. 3) Storing users' ID together with their location may be subject to privacy legislation — be sure to consult relevant legal guidelines to ensure your implementation is compliant, and don't save/persist anything you don't absolutely have to. \$\endgroup\$
    – DMGregory
    Commented Mar 12, 2020 at 13:39
  • \$\begingroup\$ @DMGregory 100% on that third point. With the system I built, we didn't use location, so the only data being passed around with the requests was the userIDs which are anonymous data. This is another benefit of keeping the data server-side and providing only the bare minimum information to the client-end about another client. really the only information aside from the traded items should be an anonymous user-ID and their public username. Not even their location data needs to be passed along, it's enough that the server knows they're nearby. \$\endgroup\$ Commented Mar 12, 2020 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .