Page 1 of 1

Accessing position in MMORoom

Posted: 18 Jun 2014, 11:06
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?

Re: Accessing position in MMORoom

Posted: 18 Jun 2014, 15:59
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

Re: Accessing position in MMORoom

Posted: 22 Feb 2016, 23:28
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?

Re: Accessing position in MMORoom

Posted: 23 Feb 2016, 09:23
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