|
player - a player ID, a bot's included entity - a shared entity, or 0 to take the player's entity away predict (optional) - True to let the player's own copy move the entity at once from their own input; False to have it wait for the server; left out, True for an entity with a Marble or Walker behaviour and False otherwise (default) |
|
Gives a player the entity they play as, on a server room's server. In a server room the server owns every entity, players' too: spawn or share an entity for each player who joins, then give it to them here. Every copy then finds it with SharedPlayerEntity, for its camera, its name tags or its own player's marker. An entity belongs to one player at a time. When a player leaves, or the entity is freed or unshared, the player has no entity any more. Free a departed player's entity yourself when you get SHARED_EVENT_PLAYER_LEFT. Without prediction, a player's own marble or character moves a round trip after they press a key: their input goes to the server, and the server's move comes back. With prediction, their copy moves it at once, as the server will, and the server corrects any difference: the copy's own movement code runs there too, since SharedPlayerDriven is True for that player, and a Marble or Walker behaviour steers it. Small corrections slide in over about a fifth of a second, and big ones (more than 5 units) snap. Copies of other objects with bodies become solid where they are now, so a bump happens at once too; a shove from someone else still arrives a round trip late. On the player's copy, a copy of an object of the world (an "entity:" prefab, as the World Editor's player object is) gets that object's body and behaviours. A copy of a model asset gets nothing, so give it what your movement code needs, such as EntityPhysics, once SharedPlayerDriven turns True. Prediction works best with one UpdateWorld for each 60th of a second, as the server steps. Bots are never predicted. Share the entity first, with SpawnSharedEntity or ShareWorldEntity; otherwise nothing changes and SharedWorldError() says why. For the full story - server rooms, hosting, sharing and host migration - see the Shared World guide and its complete Shared_World_Playground.bb sample. See also: SharedPlayerEntity, SpawnSharedEntity, ShareWorldEntity, AddSharedBot, SharedPlayerDriven, SharedRoomRange. |