Accessing position in MMORoom

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
User avatar
Flying_Banana
Posts: 42
Joined: 04 May 2014, 07:03

Accessing position in MMORoom

Post by Flying_Banana »

I'd like to keep track of all the players' positions in an MMORoom, not just for the server to send messages based on AOI, but also for game calculations and such. After a quick browse through the API, I couldn't find any reference to getting a player's position in the MMORoom. Should I just store the position again in the user variables? But that seems to be a little redundant...

So do we have to do:
Client sends new user position to server
Server validates position, and updates MMORoom user position.
Server sets user variables.
Other clients receive updates.

And then for all game calculations we use user variables?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Accessing position in MMORoom

Post by Lapo »

It depends... If the position is required as an information on the client side then you can use UserVars, otherwise there's no need for that. You can simply store the position via the User.set/getProperty(...) methods.

Normally you will need the position as UserVars, though. Otherwise how you're going to know where to render the players on screen?
You can take a look at the two examples we have in our Flash Example pack (or Unity example pack). In particular the SpaceWar game.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
abush
Posts: 13
Joined: 11 Feb 2016, 18:40

Re: Accessing position in MMORoom

Post by abush »

I'm running into the same situation of needing to track seemingly redundant data.

I have a custom command for player positional updates which modifies the MMOApi user position and then is broadcast to all clients within the AOI. When another user enters the AOI the PROXIMITY_LIST_UPDATE event on the client contains the MMOApi user position which is used to render the player's initial position and the custom positional update commands are used to update the rendered position while within the AOI.

Where this breaks down in when I need to confirm the player's position on the server side. I could track the user's position as a user property, however there is a findUserLocation call, that appears to expose that data but returns a P3D object who's implementation isn't exposed via the sfs2x libs.

Is it practical for the findUserLocation function to work outside of the lib, or given the "find" reference would it be a more expensive operation then looking up a user property?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Accessing position in MMORoom

Post by Lapo »

Hi,
abush wrote: Where this breaks down in when I need to confirm the player's position on the server side. I could track the user's position as a user property, however there is a findUserLocation call, that appears to expose that data but returns a P3D object who's implementation isn't exposed via the sfs2x libs.
no the findUserLocation method will not return anything useful. The P3D class does not deal with physical screen coordinates, instead it keeps track of the sector in which each user is located. These sectors allow to determine which users fall within the AOI of a specific target. That's why none of this is exposed in the API.

I would recommend storing the last position of each user on the server side via setProperty(...).

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply