Players
Player is the local player: the one whose game runs this copy of your scripts. Players is everyone in the room. Each player's game sees itself as Player, so what a script does to Player happens to that player only.
using NodeWorld.Flux;
namespace MyWorld
{
public class Welcome : FluxScript
{
public Text board;
protected override void Start() => Show();
protected override void OnPlayerJoined(int playerId) => Show();
protected override void OnPlayerLeft(int playerId) => Show();
private void Show()
{
var names = "";
foreach (var id in Players.ids)
names += Players.GetName(id) + (Players.IsMaster(id) ? " (master)" : "") + "\n";
board.text = names;
}
}
}The local player
Player.id | Their id in the room (0 on the server, which has no local player). |
Player.name, Player.accountId | Their display name, and their NodeWorld account: the same in every room and every visit, to give rights to some accounts. |
Player.language | The language of their game ("en", "fr"…); OnLanguageChanged(language) when they change it. |
Player.isInVR, Input.isDesktop | In a headset, or with keyboard and mouse. |
Player.isMaster | They are the master of the room. |
Player.position, Player.rotation, Player.velocity, Player.isGrounded | Where they stand and how they move. |
Player.headPosition, Player.headRotation | Their head (the camera). |
Player.GetTrackingPosition(point), GetTrackingRotation(point) | TrackingPoint.Head, LeftHand, RightHand, or Origin: the origin of their play space, on the floor. |
Player.GetBonePosition(bone), GetBoneRotation(bone) | A bone of their avatar (Bone.Head, Bone.LeftHand…), in world space; Vector3.zero without an avatar. |
Move the local player
Player.Teleport(position, yRotationDegrees) | Moves the origin of their play space there, turned. On a computer they stand on it; in VR their head keeps its place in the room. |
Player.Teleport(position, rotation) | The same, tilted: a seat that pitches and rolls with a vehicle tilts the view with it. |
Player.Respawn() | Back to the spawn point. |
Player.velocity = … | Pushes them; gravity and the ground then act. |
Player.walkSpeed, runSpeed, strafeSpeed | Their speeds. |
Player.jumpImpulse | The vertical speed of a jump, in m/s; 0: no jump. |
Player.gravityStrength | 1 normal, 0 none. |
Player.immobilized | Their input no longer moves them; your scripts still may. |
Player.PlayHaptic(hand, duration, amplitude, frequency) | Vibrates a controller in VR. |
The player can always open the menu, respawn and leave, whatever these values: their Respawn gives them back their own moves (what a script cannot block). OnPlayerRespawn() runs on every script when the local player respawns: they fell under the Respawn Height of the NW World, chose Respawn, or a script called Player.Respawn(). Set your values again there if your world needs them.
Seat the local player
Player.sittingPoint = seat puts their avatar in its sitting pose on the transform seat: its root on the point, facing its forward, following it when it moves; its head and hands still follow the player. null stands them up. Place the player yourself so their eyes are where the avatar's are: Player.sittingEyeOffset is that place from the point, in the point's space. See seats.
The other players
Players.ids | The ids of everyone in the room, the local player included, in the order they entered (the master first). |
Players.count, Players.Get(index) | The other players only, as PlayerInfo (id, name, position, rotation, headPosition). |
Players.Exists(id), GetName(id), GetAccountId(id), IsMaster(id), GetJoinOrder(id) | One player by id; GetJoinOrder is 0 for the first still there, -1 for a player who is not. |
Players.GetPosition(id), GetRotation(id), GetVelocity(id), GetBonePosition(id, bone), GetBoneRotation(id, bone), GetTrackingPosition(id, point), GetTrackingRotation(id, point) | Their pose. |
OnPlayerJoined(playerId) and OnPlayerLeft(playerId) run on every script when another player enters or leaves the room; OnMasterChanged(masterId) when the master changes.
Avatars are not reachable by scripts: you read their bones and pose, you do not change them.
Voices
How the local player hears another player, set by your scripts on each player's game:
// The players on the stage are heard across the hall.
Players.SetVoice(singerId, new VoiceSettings { near = 10f, far = 60f, gain = 6f, volumetricRadius = 2f, lowpass = false });VoiceSettings | |
|---|---|
near | Distance (m) up to which the voice is at full volume. |
far | Distance (m) beyond which it is not heard; 0: not heard at all. |
gain | Gain in dB; 0: as it is. |
volumetricRadius | Radius (m) of the voice's source; a large one sounds less like a point. |
lowpass | Muffles a far voice. |
Players.SetVoiceNear, SetVoiceFar, SetVoiceGain, SetVoiceVolumetricRadius and SetVoiceLowpass change one value; ResetVoice(id) goes back to the game's own settings (Players.defaultVoice); GetVoice(id) reads what your scripts set. Players.SetAvatarAudible(id, false) silences the sounds of that player's avatar for the local player, until the world unloads.
On the server
There is no local player on the server: Player.id is 0 and the rest of Player is refused there, and Players holds every player of the room. OnPlayerJoined and OnPlayerLeft run there too.
