Physics
Read and change the discs that make up the match, including the ball and players.
Everything that moves is a disc. During a match, disc indices list the stadium's discs first, with the ball at index 0, then the players on the pitch in roster order. Spectators have no disc. In the lobby there are no discs: reads return null or 0 and changes do nothing.
Positions and sizes use stadium units, with the origin at the centre of the pitch.
CollisionFlags
room.CollisionFlags: Readonly<Record<string, number>>Bit flags for cMask and cGroup: a disc collides with another when its cMask shares a bit with the other's cGroup.
| Flag | Value |
|---|---|
ball | 1 |
red | 2 |
blue | 4 |
redKO | 8 |
blueKO | 16 |
wall | 32 |
kick | 64 |
score | 128 |
c0 … c3 | 1 << 28 … 1 << 31 |
all | 63 |
const { ball, red, blue, wall } =
room.CollisionFlags;
// The ball passes through players;
// it collides with walls only.
await room.setDiscProperties(0, {
cMask: wall,
});getDiscCount()
room.getDiscCount(): numberReturns
numberStadium discs plus players on the pitch; 0 in the lobby.
getDiscProperties()
room.getDiscProperties(discIndex: number): HostDiscProperties | nullParameters
numberrequired0 (the ball) to getDiscCount() - 1.Returns
HostDiscProperties | nullThe disc's properties, or null for an invalid index or in the lobby.
const ball = room.getDiscProperties(0);
if (ball)
console.log(
'Ball speed',
Math.hypot(ball.xspeed, ball.yspeed),
);setDiscProperties()
room.setDiscProperties(discIndex: number, properties: DiscPropertyPatch): Promise<void>Changes a disc immediately, even while the match is paused. The whole patch is validated first: an invalid field rejects with Invalid disc property: <name> and nothing changes. Ranges:
| Fields | Range |
|---|---|
x, y, xspeed, yspeed, xgravity, ygravity | −8192 to 8192 |
radius | 0.5 to 100 |
bCoeff | −1 to 8192 |
invMass, damping | 0 to 8192 |
color | 0x000000 to 0xffffff, or -1 for transparent |
cMask, cGroup | 32-bit integers |
A change that would make collisions too expensive for the room, such as shrinking many discs, rejects with Stadium collision complexity exceeds the room budget. With an invalid index or in the lobby, the call does nothing.
Parameters
numberrequirednull fields keep their value; unknown fields are ignored.Returns
Promise<void>
// Drop the ball back on the centre spot.
await room.setDiscProperties(0, {
x: 0,
y: 0,
xspeed: 0,
yspeed: 0,
});getPlayerDiscProperties()
room.getPlayerDiscProperties(playerId: number): HostDiscProperties | nullParameters
numberrequiredReturns
HostDiscProperties | nullThe player's disc, or null for spectators, unknown players and in the lobby.
setPlayerDiscProperties()
room.setPlayerDiscProperties(playerId: number, properties: DiscPropertyPatch): Promise<void>Changes a player's disc by player ID, so you don't need to work out its index. Spectators and unknown players are ignored.
Parameters
numberrequiredReturns
Promise<void>
// A giant goalkeeper for the red team.
await room.setPlayerDiscProperties(keeper.id, {
radius: 30,
invMass: 0.2,
});