@zaisma/physics 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,14 +36,17 @@ export const valley = definePhysicsWorld({
36
36
  - **Bodies** are `moving` (physics moves them), `kinematic` (the game moves them: lifts, doors on rails, platforms) or `fixed`, made of shapes: `box`, `ball`, `capsule`, `cylinder`, `hull`, and for the fixed world `mesh` and `heightfield`. Metres, kilograms, +Y up. `setBody(id, { motionKind })` parks one or lets it go.
37
37
  - **Bodies on a timetable:** a kinematic body with a `timetable` goes between its stops by itself: a lift, a tram, a turning arm, a sweeper. 2 to 32 `stops`, each a place, a turn, how long the trip there takes and how long it waits; `repeatMode` `loop`, `back_and_forth` or `once`; `easeKind` `linear` or `smooth`. Every game and the game server work out where it is from the room's step alone, so nothing of it is sent and a step run again finds it where it was. It carries the characters and bodies standing on it and pushes what's in its way.
38
38
  - **Ground for a big map:** a heightfield or a mesh too big to write inline is read from a data file (`dataPath`, formats in `data.js`; name it `.bin`, a file type Zaisma's upload takes): `loadPhysicsData(world)` in a game, `readDataFile` where the world opens on a game server. Only the ground near something that moves is laid, so a 1,500 m valley costs what the few hundred metres around its players cost. `keepGroundNear(pointM)` keeps it laid where a camera or a query looks.
39
- - **Joints:** `fixed`, `ball`, `hinge`, `slider`, `spring` and `rope`, between two bodies, a body and a character, or a body and the world, with limits; declared, or added and let go while playing.
39
+ - **Joints:** `fixed`, `ball`, `hinge`, `slider`, `spring` and `rope`, between two bodies, a body and a character, or a body and the world, with limits; declared, or added and let go while playing. A hinge's angle and a slider's distance (limits and motor targets alike) are measured as the other end, or the world, seen from the body: flip the axis and the measure flips.
40
+ - **Motors and joints that break:** a hinge or slider takes a `motor` (`motorKind` `position`, to a target angle or distance with `stiffnessNumber` and `dampingNumber`, or `speed`, at a target speed, each with its `maximumForceNewtons`): a door that swings shut, a winch, a turret. `setJoint(id, { motorTargetNumber })` moves its target while playing, sent to everyone. A joint with `breakForceNewtons` lets go when pulled harder than that (a rope under a load, a trailer's hitch), tells `jointBroke` once, and `setJoint(id, { isEnabled: true })` mends it. A rigid joint to a character the game moves wants a `spring` or a break force: nothing stops the character, so the joint is all that holds what it drags against a wall.
40
41
  - **Vehicles:** a body with `wheels` and `vehicle` drives on ray-cast wheels: suspension, engine, brakes, steering. Whoever sits in seat 0 drives it from their input (`vehicleControls`, by default the stick and `isBraking`); others ride along, seated at once. Wheels never stand on characters (and only on `wheelCollisionLayerNames` when given), a heavy vehicle's springs hold its weight (`maximumSuspensionForceNewtons`), and `drawnBody` answers each wheel's spring and spin to draw it by.
41
42
  - **Bodies while playing:** `setBody` sets a body's place, speed, motion kind, layer or `massKg` (what rides in a cart's bed weighs on it); `addBody` takes a `motionKind` (a building piece placed `fixed` at once); a body or kind may slow at its own `linearDampingNumber` and `angularDampingNumber`. A world played alone frees its engine with `dispose()`.
42
43
  - **Small quick things** (lighter than 8 kg: food, stones, bullets you can see) look ahead for what they'll meet, so they hold on heightfield ground and thin walls up to about 20 m/s at the default `substepCount`; anything faster wants more substeps.
44
+ - **Zones:** places that tell who came in and left (`zoneEntered`, `zoneLeft`, `zoneOccupants(id)`, `zonesAt`): a capture point, a checkpoint, water, a door's trigger. One may turn gravity (`gravityPct`: 0 floats things, 200 doubles it), push (`pushMPerSecPerSec`: a fan, wind, a current) and slow (`dampingNumber`: water, mud), for the layers it names, and may ride on a body (`bodyId`: inside a lift). `setZone(id, { isEnabled })` switches one, sent to everyone. Bodies feel it as real forces; a character kind reads it with `stepContext.zoneEffectsOf(character)`, and the walking characters wade, float and drift by it.
45
+ - **Body kinds with rules of their own:** `bodies: { hover: { stateFields, step(body, driverInput, stepContext) } }` on `createPhysics` and `physicsKind` steps every body of a kind by the game's rules, before the engine moves the world, the mirror of a character kind: a boat, an aircraft, a bike, a hover, a mine with a fuse. Its `stateFields` are the body's own (`body.own`), sent with it; whoever sits in seat 0 is its driver, and their input is `driverInput`. A body at rest with nobody aboard isn't stepped unless `isSteppedAtRest`. `stepContext.addForce(body, forceNewtons, atM)` and `addTorque` push it for the step, through every substep, against gravity and what it leans on; `stepContext.bodyMotion(body)` reads where it is and how it moves. Up to 8 kinds may have fields of their own.
43
46
  - **Collision layers:** named, each saying what it touches, and changed while playing (`setBody`, `setCharacter`): how a ghost passes walls, or a thing goes out of play.
44
- - **Queries:** `castRay`, `castBall`, `castCapsule`, `overlapBall` and `overlapCapsule`, answering whose body or character, where, the surface's normal, which of a mesh's triangles (`triangleIndex`) and its surface (`surfaceName`); a capsule's contacts say how deep it is in each, to push a game's own movement out of walls, one a body or, with `isEachTriangle`, one for every triangle it touches. A cast writes into an object the game keeps when given one (`castRay(query, hit)`), and so do `overlapCapsule(query, contacts)` and a step's `moveAndSlide(character, movedM, moved)`, so thousands a second make nothing new.
47
+ - **Queries:** `castRay`, `castBall`, `castCapsule`, `castBox`, `overlapBall`, `overlapBox` and `overlapCapsule`, and `castRayAll` (every hit along a ray, nearest first: a shot through glass and a wall) and `castRays` (many rays in one call, from a `Float32Array`: a shotgun, sensors, a car's whiskers), answering whose body or character, where, the surface's normal, which of a mesh's triangles (`triangleIndex`) and its surface (`surfaceName`); a capsule's contacts say how deep it is in each, to push a game's own movement out of walls, one a body or, with `isEachTriangle`, one for every triangle it touches. A cast writes into an object the game keeps when given one (`castRay(query, hit)`), and so do `overlapCapsule(query, contacts)` and a step's `moveAndSlide(character, movedM, moved)`, so thousands a second make nothing new.
45
48
  - **Surfaces:** a world names its surfaces (`surfaceNames: ["grass", "metal_grate", "glass"]`), a shape says which it is (`surfaceName`) or a mesh says triangle by triangle (`triangleSurfaceIndices`), and every hit and contact answers the name: footsteps, bullet marks, tyre grip. `castBall` and `castCapsule` with `isStoppedAtPenetration: false` move out of what they start touching (a camera pressed to a wall).
46
- - **A level's collision as it ships:** a mesh takes a `Float32Array` of points and a `Uint32Array` of indices as they are, up to 2,000,000 triangles, and `triangleGroupNumbers` puts triangles in up to 63 groups the world switches on and off (`setTriangleGroup`: a door that opens, a bridge that falls). A group may sit on a collision layer of its own (`triangleGroups: [{ groupNumber: 4, collisionLayerName: "glass" }]`: glass that stops soldiers and lets shots through). The engine holds a mesh once however many worlds are made from it: every room a game server copy runs, a menu's world and the match's.
49
+ - **A level's collision as it ships:** a mesh takes a `Float32Array` of points and a `Uint32Array` of indices as they are, up to 2,000,000 triangles (built in tiles past 65,536, so opening one needs little more memory than the 94 bytes a triangle it ends up holding), and `triangleGroupNumbers` puts triangles in up to 63 groups the world switches on and off (`setTriangleGroup`: a door that opens, a bridge that falls). A group may sit on a collision layer of its own (`triangleGroups: [{ groupNumber: 4, collisionLayerName: "glass" }]`: glass that stops soldiers and lets shots through). The engine holds a mesh once however many worlds are made from it: every room a game server copy runs, a menu's world and the match's.
47
50
  - **The engine itself:** `physicsEngine()` answers Rapier as the piece ships it; `rapier/rapier.d.ts` types all of it (what a game uses most closely, the rest loosely). A body a game makes straight in the engine (`stepContext.rapierWorld`) isn't the piece's: it's never sent, nor put back on a replay, so online it differs in every game. Declare it (or add it with `addBody`), or hold it to a character with a joint (`otherBodyId`), and it's shared like any other; keep the engine's own for what's only drawn.
48
51
 
49
52
  ## Characters
@@ -74,6 +77,12 @@ export const soldiers = defineCharacterKind({
74
77
 
75
78
  Its fields ride the wire with the character's own, so a replay runs it exactly; a field with `isShared: false` is each game's own memory instead (sprinting, stopped at deep water), worked out by each step and never sent. `stepContext` has `moveAndSlide`, the queries, `bodyState` and `characterState` to read what's around, `setJoint` to take or let go a cart's handles and `setLayer` to walk through it while held (both run again exactly on a replay), `emit`, `isInCharge`, `isReplay` and the engine. `stepRiding` keeps a seated character's own fields going. A character rests (and isn't sent) only on a step that changed none of its own fields, a rider with its vehicle parked. `vehicleControls(input, vehicle, stepContext)` reads the vehicle as `bodyState` does, with its `bodyId`. `canPushBodies: false` walks into a parked cart without shoving it. A kinematic character moves through the engine's substeps at its speed, so what it pulls on a joint is carried at that speed and what it walks into is pushed, not shoved. A kind can also step bodies before and after the world (`beforeWorldStep`, `afterWorldStep`), drive vehicles its way, and add calls, settings and hooks of its own: that's how `@zaisma/physics-party` is built. Every hook is in `index.d.ts`, and a game's shared declarations import `world.js` (typed by `world.d.ts`).
76
79
 
80
+ `moveAndSlide` slides along every surface it touches at once and answers no move only in a corner or straight at a wall (since 2.7.0; before, a walker along a wall or on ground far from the world's middle could be answered nothing for a step, on steps that turned on a tenth of a millimetre). A replay agrees with the game server only as far as the world does: a step that turns on a hair (whether a foot clears a step's edge, which side of a corner it goes) may go one way in a player's game and the other on the server, so a kind's own thresholds (a stamina running dry) want no tolerance, and its moves hold up best kept a skin's width off walls.
81
+
82
+ **Sizes.** The world's `character` is the size every character starts as, and `characterSizes` names the others: `[{ name: "crouched", heightM: 1 }, { name: "giant", heightM: 4, radiusM: 0.8, stepHeightM: 0.8 }]`. A step takes one with `stepContext.setSize(character, "crouched")` (`null` for the world's own) and is answered `false` where it has no room, so a soldier who lets go of crouch under a low roof stays crouched until he's out. `addCharacter(id, { characterSizeName })` adds one at its size and `setCharacter(id, { characterSizeName })` sets it at once. The feet stay where they are, every side runs it the same, and `characterState` and `drawnCharacter` say `characterSizeName`. Since 2.6.0 every character has a `sizeNumber` field of its own, so a kind's own field takes another name.
83
+
84
+ **Standing still costs nothing.** A walker with nothing asked of it, standing on what never moves, skips its move, so a crowd costs what its moving part costs. A kind of the game's own does the same by returning early when `stepContext.isRestingOnLevel(character)` is true and it has nothing to do.
85
+
77
86
  ## Characters over a level
78
87
 
79
88
  A shooter's soldiers each move on their own: only their own player predicts them, everyone else draws them a moment behind, and a hit is judged by what the shooter saw. `levelCharactersKind` is that, over a world's level (its fixed and kinematic bodies), with a game's own character kind for the rules:
@@ -145,29 +154,68 @@ Opened like every piece's ([`@zaisma/piece`](../piece)), and changed while playi
145
154
  | `walkSpeedMPerSec`, `jumpHeightM` | the walking characters' speed and jump; a kind of the game's own reads them as `tuning` |
146
155
  | `characterMassKg` | how heavy a character is beside what it pushes |
147
156
 
148
- Online, whoever runs the world decides them. Hooks: `beforePutBack` (where something that fell out of the world comes back) and `bodyHit` (for a thud or dust). A character kind adds its own (`characterSettings`, `characterHooks`).
157
+ Online, whoever runs the world decides them. Hooks: `beforePutBack` (where something that fell out of the world comes back), `bodyHit` (for a thud or dust), `zoneEntered` and `zoneLeft`, and `jointBroke`. A character kind adds its own (`characterSettings`, `characterHooks`).
158
+
159
+ ## Limits
160
+
161
+ What one world holds, each with what it costs at the limit (measured as below):
162
+
163
+ | What | At most | At the limit |
164
+ | --- | --- | --- |
165
+ | Bodies that move or may (moving, kinematic, and every one added while playing) | 2,000 | all at rest: 0.25 ms a step |
166
+ | Fixed bodies: a level's pieces, never sent, never counted with the others | 20,000 | 62 MB, opens in 0.14 s, 0.13 ms a step with 500 crates at rest on them |
167
+ | Characters, players' and the game's own, each its own size | 250 | all walking: 3.7 ms a step; all standing: 0.35 ms |
168
+ | Joints | 1,000 | |
169
+ | Triangles in one mesh from typed arrays or a data file | 2,000,000 | 190 MB, opens in 0.55 s, a ray 1.75 µs |
170
+ | Zones, each of up to 8 shapes | 250 | every one full of things: 1.1 ms more a step |
171
+ | Body kinds with fields and a step of their own | 8 | 500 hover craft: 0.50 ms a step (plain bodies: 0.34) |
172
+ | Hits answered along one ray | 256 | through a heap: about 4 µs |
173
+ | Rays asked in one call | 65,536 | 0.50 µs a ray (0.63 one at a time) |
174
+
175
+ A world declares at most 2,048 bodies that aren't fixed and joints together (what the online core takes from the start); the rest are added while playing. Costs follow what moves: a body asleep, a character standing still and a level's pieces take almost nothing from a step. A game server copy holds 128 MB in all, so a world with a game server stays under about a million mesh triangles, or 20,000 pieces with a smaller mesh.
149
176
 
150
177
  ## Measured
151
178
 
152
- What the piece costs, measured on a MacBook (Apple M5, 10 cores) with other work running, on version 2.5.0 (December 4, 2026). `node --expose-gc scripts/physics-bench.mjs` in Zaisma's repository measures it again.
179
+ What the piece costs, measured on a MacBook (Apple M5, 10 cores) with other work running, on version 2.6.0 (December 4, 2026), and a game's own rules on 2.7.0 (December 5, 2026). `node --expose-gc scripts/physics-bench.mjs` in Zaisma's repository measures it again.
153
180
 
154
181
  | What | Measured |
155
182
  | --- | --- |
156
- | A step of 999 crates falling, 2 substeps | 6.1 ms; the engine alone takes 5.8 (1.04 times); through a game server's room 8.0 |
157
- | The same 999 at rest | 0.14 ms |
158
- | Garbage a step leaves, 999 crates | 5 to 10 KB (2.4.1 left 7.5 MB) |
159
- | 999 things spread over a 1 km heightfield, falling | 6.4 ms a step, worst 10.5; at rest 0.2 ms |
160
- | 64 characters walking | 0.9 ms a step |
161
- | 8 players and 300 crates kept moving, to one player | 9.7 KB a second down, 0.6 up |
183
+ | A step of 999 crates falling, 2 substeps | 6.1 ms; the engine alone takes 5.7 (1.04 times); through a game server's room 7.4 |
184
+ | The same 999 at rest | 0.07 ms |
185
+ | Garbage a step leaves, 999 crates | 5 to 9 KB (2.4.1 left 7.5 MB) |
186
+ | 999 things spread over a 1 km heightfield, falling | 5.6 ms a step, worst 9.2; at rest 0.1 ms |
187
+ | 500 crates on a level of 1,000 fixed pieces | opens in 29 ms; 1.7 ms a step falling, 0.05 at rest |
188
+ | The same on 20,000 fixed pieces | opens in 136 ms; 2.9 ms a step falling, 0.13 at rest; 3.1 KB a piece |
189
+ | 64 characters walking | 0.7 ms a step |
190
+ | 250 characters walking | 3.7 ms a step; standing still, 0.35 |
191
+ | A mesh of 500,000 triangles, built in tiles | 52 MB; 94 bytes a triangle |
192
+ | 8 players and 300 crates kept moving, to one player | 9.6 KB a second down, 0.6 up |
193
+ | 999 crates heaping under 250 zones, 3,030 crates inside them | 6.2 ms a step falling (5.0 without the zones), 6.0 heaped (4.9) |
194
+ | 10,000 rays in one call (`castRays`) | 0.50 µs a ray, 5 KB of garbage the call; one at a time 0.63 µs |
195
+ | A box cast, and every hit along a ray (16 on average) | about 4 µs each |
196
+ | 500 hover craft held up by a step of their own, two fields each | 0.50 ms a step (500 plain bodies falling: 0.34) |
197
+ | 500 bobs on ropes that could break | 0.76 ms a step (on ropes that can't: 0.70) |
162
198
 
163
199
  A shooter's real levels, beside that shooter's own collision code written for nothing else (Shieldbreak: the same 20,000 rays and capsules through both):
164
200
 
165
201
  | Level | Triangles | Memory | Opens in | A second room | A ray | A capsule's contacts |
166
202
  | --- | --- | --- | --- | --- | --- | --- |
167
- | Cascade | 72,442 | 6.5 MB (its own: 5.7) | 37 ms (35) | 0.04 MB, 5 ms | 1.1 µs (1.3) | 2.1 µs (2.3) |
168
- | Liftoff | 48,696 | 4.4 MB (1.6) | 22 ms (22) | 0.04 MB, 3 ms | 1.2 µs (1.4) | 1.9 µs (1.9) |
169
- | Caldera | 99,087 | 9.0 MB (7.9) | 45 ms (43) | 0.04 MB, 6 ms | 1.4 µs (1.3) | 1.8 µs (2.0) |
203
+ | Cascade | 72,442 | 6.5 MB (its own: 5.7) | 27 ms (24) | 0.04 MB, 3 ms | 0.66 µs (0.64) | 1.3 µs (1.3) |
204
+ | Liftoff | 48,696 | 4.4 MB (1.0) | 12 ms (10) | 0.04 MB, 2 ms | 0.72 µs (0.81) | 0.9 µs (1.0) |
205
+ | Caldera | 99,087 | 9.0 MB (7.9) | 34 ms (23) | 0.04 MB, 4 ms | 0.85 µs (0.71) | 1.2 µs (1.2) |
170
206
 
171
207
  Every ray answered the same as the shooter's own, and a query leaves 100 to 300 bytes of garbage.
172
208
 
209
+ On a phone (an iPhone on iOS 27.2, over https), in the browser:
210
+
211
+ | What | Measured |
212
+ | --- | --- |
213
+ | A step of 250 crates falling | 0.9 ms |
214
+ | 500 crates falling | 1.9 ms |
215
+ | 999 crates falling | 4.3 ms, worst 9; at rest 0.07 |
216
+ | 64 characters walking | 0.7 ms a step |
217
+ | A level of 100,352 triangles | opens in 35 ms; a ray 0.73 µs, a capsule's contacts 1.0 µs |
218
+
219
+ Since iOS 27 an iPhone runs a page opened over plain `http://` (a computer's Wi-Fi address while testing) without its compiler, about 20 times slower, in every browser. Test on a phone over https; a published game always is.
220
+
173
221
  `index.d.ts`, `server.d.ts` and `rapier/rapier.d.ts` (the engine, through `physicsEngine()`) are the reference. How pieces work: [docs/PIECES.md](https://github.com/zaisma/zaisma-sdk/blob/main/docs/PIECES.md). PolyForm Shield 1.0.0 licensed (`LICENSE.txt`): use it in any game, sold or free, on Zaisma, on your own server or anywhere else; only a product that competes with it, or with what Zaisma makes with it, is ruled out. Versions before 2.4.0 were MIT licensed and stay so; Rapier is Apache-2.0 licensed (`rapier/LICENSE.txt`).
package/batch.js CHANGED
@@ -16,6 +16,11 @@ export const CONTACT_FLOAT_COUNT = 10;
16
16
  /** Whole numbers for one contact: its owner's tag, which triangle (or NO_TRIANGLE_INDEX) and which collider. */
17
17
  export const CONTACT_NUMBER_COUNT = 3;
18
18
 
19
+ /** Floats for one of a ray's hits: how far (1) and the surface's normal there (3). */
20
+ export const RAY_HIT_FLOAT_COUNT = 4;
21
+ /** How many rays castRays hands the engine in one call: each is 6 floats in, and 4 floats and 3 whole numbers out, all before the awake bodies. */
22
+ export const RAYS_PER_CALL_COUNT = 256;
23
+
19
24
  /** A tag's low bits: whose a body or a collider is. Its number is above them, from bit 8. */
20
25
  export const BODY_TAG_NUMBER = 1;
21
26
  export const CHARACTER_TAG_NUMBER = 2;
@@ -91,65 +96,116 @@ export function createBatch(engine, rapierWorld) {
91
96
  const heldByTriangleIndices = new WeakMap();
92
97
  const letGo = typeof FinalizationRegistry === "undefined" ? { register() {} } : new FinalizationRegistry((raws) => raws.forEach((raw) => raw.free()));
93
98
 
94
- /**
95
- * A mesh as a collider is made from it (new engine.ColliderDesc(mesh.shape)), built the first time it's asked for
96
- * and shared after. With groupNumbers (a group for each triangle), only groupNumber's triangles and the points they
97
- * use. Answers { shape, triangleIndexes }: triangleIndexes says which of the whole mesh's triangles each of the
98
- * shape's is, or null when they're the same. Null when the triangles make no mesh.
99
- */
100
- export function heldMesh(engine, pointsM, triangleIndices, groupNumbers = null, groupNumber = 0) {
99
+ /** A mesh of more triangles than this is built in tiles of about MESH_TILE_TRIANGLE_COUNT, side by side over its two longest sides. */
100
+ export const WHOLE_MESH_TRIANGLE_COUNT = 65536;
101
+ const MESH_TILE_TRIANGLE_COUNT = 32768;
102
+
103
+ function heldOf(pointsM, triangleIndices, groupNumbers) {
101
104
  let held = heldByTriangleIndices.get(triangleIndices);
102
105
  if (!held || held.pointsM !== pointsM || held.groupNumbers !== groupNumbers) {
103
106
  // The same triangles with other points or groups: a colliders' own hold keeps what it was made from.
104
107
  held?.raws.splice(0).forEach((raw) => raw.free());
105
- held = { pointsM, groupNumbers, raws: [], meshByGroupNumber: new Map() };
108
+ held = { pointsM, groupNumbers, raws: [], parts: null };
106
109
  heldByTriangleIndices.set(triangleIndices, held);
107
110
  letGo.register(triangleIndices, held.raws);
108
111
  }
109
- // -1 for the whole mesh, not a group of it.
110
- const heldGroupNumber = groupNumbers ? groupNumber : -1;
111
- if (held.meshByGroupNumber.has(heldGroupNumber)) return held.meshByGroupNumber.get(heldGroupNumber);
112
- let meshPointsM = pointsM;
113
- let meshTriangleIndices = triangleIndices;
114
- let triangleIndexes = null;
115
- if (groupNumbers) {
116
- let triangleCount = 0;
117
- for (let triangleIndex = 0; triangleIndex < groupNumbers.length; triangleIndex += 1) if (groupNumbers[triangleIndex] === groupNumber) triangleCount += 1;
118
- triangleIndexes = new Uint32Array(triangleCount);
119
- meshTriangleIndices = new Uint32Array(triangleCount * 3);
120
- // Only the points the group's triangles use, numbered again in the order they're met.
121
- const newPointIndexes = new Int32Array(pointsM.length / 3).fill(-1);
112
+ return held;
113
+ }
114
+
115
+ /** Which tile each triangle of a big mesh is in, by where its middle is: [tileNumbers, tileCount]. */
116
+ function tilesOf(pointsM, triangleIndices) {
117
+ const triangleCount = triangleIndices.length / 3;
118
+ const lowestM = [Infinity, Infinity, Infinity];
119
+ const highestM = [-Infinity, -Infinity, -Infinity];
120
+ for (let index = 0; index < pointsM.length; index += 1) {
121
+ const axisIndex = index % 3;
122
+ if (pointsM[index] < lowestM[axisIndex]) lowestM[axisIndex] = pointsM[index];
123
+ if (pointsM[index] > highestM[axisIndex]) highestM[axisIndex] = pointsM[index];
124
+ }
125
+ // Tiles over the mesh's two longest sides: a level spreads over its ground, a tower over its height.
126
+ const [firstAxisIndex, secondAxisIndex] = [0, 1, 2].sort((firstIndex, secondIndex) => highestM[secondIndex] - lowestM[secondIndex] - (highestM[firstIndex] - lowestM[firstIndex]));
127
+ const sideTileCount = Math.ceil(Math.sqrt(triangleCount / MESH_TILE_TRIANGLE_COUNT));
128
+ const tileOf = (axisIndex, triangleIndex) => {
129
+ const middleM = (pointsM[triangleIndices[triangleIndex * 3] * 3 + axisIndex] + pointsM[triangleIndices[triangleIndex * 3 + 1] * 3 + axisIndex] + pointsM[triangleIndices[triangleIndex * 3 + 2] * 3 + axisIndex]) / 3;
130
+ const lengthM = highestM[axisIndex] - lowestM[axisIndex];
131
+ return lengthM > 0 ? Math.min(Math.floor(((middleM - lowestM[axisIndex]) / lengthM) * sideTileCount), sideTileCount - 1) : 0;
132
+ };
133
+ const tileNumbers = new Uint32Array(triangleCount);
134
+ for (let triangleIndex = 0; triangleIndex < triangleCount; triangleIndex += 1) tileNumbers[triangleIndex] = tileOf(firstAxisIndex, triangleIndex) * sideTileCount + tileOf(secondAxisIndex, triangleIndex);
135
+ return [tileNumbers, sideTileCount * sideTileCount];
136
+ }
137
+
138
+ /**
139
+ * A mesh as colliders are made from it (new engine.ColliderDesc(part.shape)), built the first time it's asked for
140
+ * and shared after: a part for each of its triangle groups (groupNumbers, a group for each triangle; one group when
141
+ * null), and a big mesh's groups in tiles, so building it never needs much more memory than it ends up holding.
142
+ * Answers [{ groupNumber, shape, triangleIndexes }]: triangleIndexes says which of the whole mesh's triangles each of
143
+ * the part's is, or null when they're the same. Empty when the triangles make no mesh.
144
+ */
145
+ export function heldMeshParts(engine, pointsM, triangleIndices, groupNumbers = null) {
146
+ const held = heldOf(pointsM, triangleIndices, groupNumbers);
147
+ if (held.parts) return held.parts;
148
+ held.parts = [];
149
+ const triangleCount = triangleIndices.length / 3;
150
+ if (triangleCount === 0) return held.parts;
151
+ const addPart = (groupNumber, partPointsM, partTriangleIndices, triangleIndexes) => {
152
+ const raw = new engine.TriMesh(partPointsM, partTriangleIndices).intoRaw();
153
+ if (!raw) return;
154
+ held.raws.push(raw);
155
+ // A collider takes its own hold on the shape and frees it once it's made: the one kept here stays.
156
+ held.parts.push({ groupNumber, shape: { type: engine.ShapeType.TriMesh, intoRaw: () => engine.RawBatch.sharedShape(raw) }, triangleIndexes });
157
+ };
158
+ const isBig = triangleCount > WHOLE_MESH_TRIANGLE_COUNT;
159
+ if (!groupNumbers && !isBig) {
160
+ addPart(0, pointsM, triangleIndices, null);
161
+ return held.parts;
162
+ }
163
+ const [tileNumbers, tileCount] = isBig ? tilesOf(pointsM, triangleIndices) : [null, 1];
164
+ // The triangles in the order of their parts (a group's tile), each part's in the mesh's own order.
165
+ let highestGroupNumber = 0;
166
+ if (groupNumbers) for (let triangleIndex = 0; triangleIndex < triangleCount; triangleIndex += 1) if (groupNumbers[triangleIndex] > highestGroupNumber) highestGroupNumber = groupNumbers[triangleIndex];
167
+ const partNumberOf = (triangleIndex) => (groupNumbers ? groupNumbers[triangleIndex] : 0) * tileCount + (tileNumbers ? tileNumbers[triangleIndex] : 0);
168
+ const firstIndexes = new Uint32Array((highestGroupNumber + 1) * tileCount + 1);
169
+ for (let triangleIndex = 0; triangleIndex < triangleCount; triangleIndex += 1) firstIndexes[partNumberOf(triangleIndex) + 1] += 1;
170
+ for (let partNumber = 0; partNumber + 1 < firstIndexes.length; partNumber += 1) firstIndexes[partNumber + 1] += firstIndexes[partNumber];
171
+ const orderedTriangleIndexes = new Uint32Array(triangleCount);
172
+ const writtenCounts = new Uint32Array(firstIndexes.length);
173
+ for (let triangleIndex = 0; triangleIndex < triangleCount; triangleIndex += 1) {
174
+ const partNumber = partNumberOf(triangleIndex);
175
+ orderedTriangleIndexes[firstIndexes[partNumber] + writtenCounts[partNumber]] = triangleIndex;
176
+ writtenCounts[partNumber] += 1;
177
+ }
178
+ // Only the points a part's triangles use, numbered again in the order they're met. Which part last took a point
179
+ // is noted beside its new number, so neither list is cleared between parts.
180
+ const newPointIndexes = new Uint32Array(pointsM.length / 3);
181
+ const takenByPartNumbers = new Uint32Array(pointsM.length / 3);
182
+ for (let partNumber = 0; partNumber + 1 < firstIndexes.length; partNumber += 1) {
183
+ const partTriangleCount = firstIndexes[partNumber + 1] - firstIndexes[partNumber];
184
+ if (partTriangleCount === 0) continue;
185
+ const triangleIndexes = orderedTriangleIndexes.slice(firstIndexes[partNumber], firstIndexes[partNumber + 1]);
186
+ const partTriangleIndices = new Uint32Array(partTriangleCount * 3);
122
187
  let pointCount = 0;
123
- let writtenCount = 0;
124
- for (let triangleIndex = 0; triangleIndex < groupNumbers.length; triangleIndex += 1) {
125
- if (groupNumbers[triangleIndex] !== groupNumber) continue;
126
- triangleIndexes[writtenCount] = triangleIndex;
127
- for (let cornerIndex = 0; cornerIndex < 3; cornerIndex += 1) {
128
- const pointIndex = triangleIndices[triangleIndex * 3 + cornerIndex];
129
- if (newPointIndexes[pointIndex] === -1) {
130
- newPointIndexes[pointIndex] = pointCount;
131
- pointCount += 1;
132
- }
133
- meshTriangleIndices[writtenCount * 3 + cornerIndex] = newPointIndexes[pointIndex];
188
+ for (let cornerIndex = 0; cornerIndex < partTriangleIndices.length; cornerIndex += 1) {
189
+ const pointIndex = triangleIndices[triangleIndexes[Math.floor(cornerIndex / 3)] * 3 + (cornerIndex % 3)];
190
+ if (takenByPartNumbers[pointIndex] !== partNumber + 1) {
191
+ takenByPartNumbers[pointIndex] = partNumber + 1;
192
+ newPointIndexes[pointIndex] = pointCount;
193
+ pointCount += 1;
134
194
  }
135
- writtenCount += 1;
195
+ partTriangleIndices[cornerIndex] = newPointIndexes[pointIndex];
136
196
  }
137
- meshPointsM = new Float32Array(pointCount * 3);
138
- for (let pointIndex = 0; pointIndex < newPointIndexes.length; pointIndex += 1) {
139
- const newPointIndex = newPointIndexes[pointIndex];
140
- if (newPointIndex === -1) continue;
141
- meshPointsM[newPointIndex * 3] = pointsM[pointIndex * 3];
142
- meshPointsM[newPointIndex * 3 + 1] = pointsM[pointIndex * 3 + 1];
143
- meshPointsM[newPointIndex * 3 + 2] = pointsM[pointIndex * 3 + 2];
197
+ const partPointsM = new Float32Array(pointCount * 3);
198
+ for (let cornerIndex = 0; cornerIndex < partTriangleIndices.length; cornerIndex += 1) {
199
+ const pointIndex = triangleIndices[triangleIndexes[Math.floor(cornerIndex / 3)] * 3 + (cornerIndex % 3)];
200
+ const newPointIndex = partTriangleIndices[cornerIndex];
201
+ partPointsM[newPointIndex * 3] = pointsM[pointIndex * 3];
202
+ partPointsM[newPointIndex * 3 + 1] = pointsM[pointIndex * 3 + 1];
203
+ partPointsM[newPointIndex * 3 + 2] = pointsM[pointIndex * 3 + 2];
144
204
  }
205
+ addPart(Math.floor(partNumber / tileCount), partPointsM, partTriangleIndices, triangleIndexes);
145
206
  }
146
- const raw = meshTriangleIndices.length ? new engine.TriMesh(meshPointsM, meshTriangleIndices).intoRaw() : undefined;
147
- let mesh = null;
148
- if (raw) {
149
- held.raws.push(raw);
150
- // A collider takes its own hold on the shape and frees it once it's made: the one kept here stays.
151
- mesh = { shape: { type: engine.ShapeType.TriMesh, intoRaw: () => engine.RawBatch.sharedShape(raw) }, triangleIndexes };
152
- }
153
- held.meshByGroupNumber.set(heldGroupNumber, mesh);
154
- return mesh;
207
+ return held.parts;
155
208
  }
209
+
210
+ /** Whether a mesh is built in tiles: more triangles than one collider is made from. */
211
+ export const isBigMesh = (triangleIndices) => triangleIndices.length / 3 > WHOLE_MESH_TRIANGLE_COUNT;
package/bodies.js ADDED
@@ -0,0 +1,72 @@
1
+ // Body kinds with rules of their own: how a kind of body in a physics world behaves beyond what physics does to it.
2
+ // The world says what each kind of body is made of (its bodyKinds: shapes, mass, seats); a game gives a kind its own
3
+ // fields and a step, run once a fixed step for each body of that kind, the same in every player's game and on the
4
+ // game server: a boat that floats and is steered, an aircraft, a hover bike, a turret that tracks, a mine that
5
+ // counts down. The step pushes its body with forces (stepContext.addForce, addTorque), reads the world with the
6
+ // same queries a character kind's step has, and keeps what it must remember in the body's own fields, which go on
7
+ // the wire like the body's place.
8
+ import { startValueOf } from "./characters.js";
9
+ import { refuse } from "./declare.js";
10
+
11
+ /** The fields every body shares whatever its kind: a kind's own fields take other names. */
12
+ export const BODY_BASE_FIELD_NAMES = ["x", "y", "z", "rotation", "velocityX", "velocityY", "velocityZ", "spinX", "spinY", "spinZ", "bodyNumber", "bodyKindNumber", "layerNumber", "motionNumber", "steerNumber", "massKg"];
13
+ /** How many of a world's body kinds may have fields of their own: each is a kind of thing of its own on the wire. */
14
+ export const MAXIMUM_OWN_FIELD_BODY_KIND_COUNT = 8;
15
+ const BEHAVIOR_KEYS = ["stateFields", "step", "isSteppedAtRest"];
16
+ const FIELD_NAME_PATTERN = /^[a-z][A-Za-z0-9]{0,39}$/;
17
+
18
+ const isPlainObject = (given) => given !== null && typeof given === "object" && !Array.isArray(given);
19
+
20
+ /**
21
+ * The rules a game gives its world's body kinds, checked: { <bodyKindName>: { stateFields, step, isSteppedAtRest } }.
22
+ *
23
+ * - stateFields: what the kind keeps of each body beyond the piece's own (its throttle, its fuel, its fuse), as
24
+ * @zaisma/net's fields: shared on the wire, so every side steps from the same. Left out, it keeps nothing.
25
+ * - step(body, driverInput, stepContext): one fixed step of one body, before the engine moves the world. body has
26
+ * id, bodyKindName, own (the kind's fields, change them in place), driverCharacterId (who sits in its first seat,
27
+ * or null) and rigidBody (the engine's). driverInput is that character's input this step, null with nobody
28
+ * there. stepContext has what a character kind's step has (the queries, bodyState, characterState, setJoint,
29
+ * tickDurationSec, tuning, isInCharge, isReplay, emit) and bodyMotion(body) (its place, rotation, speed and spin
30
+ * now), addForce(body, forceNewtons, atM) and addTorque(body, torqueNewtonMetres), which push for this one step.
31
+ * - isSteppedAtRest: true to step a body of this kind even while it lies at rest with nobody in its first seat (a
32
+ * mine's fuse, a turret that watches). By default such a body isn't stepped, and costs nothing.
33
+ *
34
+ * Answers the rules by the world's body kind numbers (a list with gaps), or null when there are none.
35
+ */
36
+ export function defineBodyBehaviors(given, world) {
37
+ if (given === undefined) return null;
38
+ if (!isPlainObject(given)) refuse("bad_body_behavior", "bodies isn't an object of rules by body kind.", "bodies", 'Give { <a name in the world\'s bodyKinds>: { stateFields, step } }, or leave bodies out.');
39
+ const behaviors = [];
40
+ let ownFieldKindCount = 0;
41
+ for (const [bodyKindName, each] of Object.entries(given)) {
42
+ const what = `bodies.${bodyKindName}`;
43
+ const bodyKindNumber = world.bodyKinds.findIndex((bodyKind) => bodyKind.name === bodyKindName) + 1;
44
+ if (bodyKindNumber === 0) refuse("bad_body_behavior", `bodies names "${bodyKindName}", which isn't one of the world's bodyKinds.`, what, world.bodyKinds.length ? `Use one of: ${world.bodyKinds.map((bodyKind) => bodyKind.name).join(", ")}.` : "Declare the kind in the world's bodyKinds first, in the game and on its game server.");
45
+ if (!isPlainObject(each)) refuse("bad_body_behavior", `${what} isn't an object.`, what, "Give { stateFields, step }.");
46
+ for (const key of Object.keys(each)) if (!BEHAVIOR_KEYS.includes(key)) refuse("bad_body_behavior", `${what} has no "${key}".`, `${what}.${key}`, `It takes: ${BEHAVIOR_KEYS.join(", ")}.`);
47
+ const { stateFields = [], step, isSteppedAtRest = false } = each;
48
+ if (typeof step !== "function") refuse("bad_body_behavior", `${what}.step isn't a function.`, `${what}.step`, "Give step(body, driverInput, stepContext): one fixed step of one body of this kind.");
49
+ if (typeof isSteppedAtRest !== "boolean") refuse("bad_body_behavior", `${what}.isSteppedAtRest isn't true or false.`, `${what}.isSteppedAtRest`, "Give true to step a body of this kind while it lies at rest with nobody in its first seat, or leave it out.");
50
+ if (!Array.isArray(stateFields) || stateFields.some((field) => !isPlainObject(field) || typeof field.name !== "string" || !FIELD_NAME_PATTERN.test(field.name))) refuse("bad_body_behavior", `${what}.stateFields isn't a list of fields.`, `${what}.stateFields`, 'Give fields as @zaisma/net takes them, like [{ name: "throttleNumber", valueKind: "number", minimumNumber: -1, maximumNumber: 1, stepSizeNumber: 0.01 }], or leave it out.');
51
+ for (const field of stateFields) {
52
+ if (BODY_BASE_FIELD_NAMES.includes(field.name)) refuse("bad_body_behavior", `${what}.stateFields names "${field.name}", which every body has already.`, `${what}.stateFields`, `Give your own fields other names than: ${BODY_BASE_FIELD_NAMES.join(", ")}.`);
53
+ if (Array.isArray(field.fields) || field.isShared !== undefined) refuse("bad_body_behavior", `${what}.stateFields' "${field.name}" is a group of fields, or says isShared.`, `${what}.stateFields`, "Give plain fields, each shared on the wire: what only one game needs to remember, it keeps itself by the body's id.");
54
+ }
55
+ if (stateFields.length) ownFieldKindCount += 1;
56
+ if (ownFieldKindCount > MAXIMUM_OWN_FIELD_BODY_KIND_COUNT) refuse("bad_body_behavior", `More than ${MAXIMUM_OWN_FIELD_BODY_KIND_COUNT} body kinds have stateFields of their own.`, "bodies", `Give at most ${MAXIMUM_OWN_FIELD_BODY_KIND_COUNT} kinds their own fields: kinds that keep the same things can be one kind, and a kind with only a step counts for none.`);
57
+ const fieldNames = stateFields.map((field) => field.name);
58
+ behaviors[bodyKindNumber] = {
59
+ bodyKindName,
60
+ bodyKindNumber,
61
+ stateFields,
62
+ fieldNames,
63
+ step,
64
+ isSteppedAtRest,
65
+ /** Which kind of thing a body of this kind is on the wire: one of its own when it has fields of its own. */
66
+ entityKindName: stateFields.length ? `body_kind_${bodyKindNumber}` : "body",
67
+ /** Each body's own fields as they start. */
68
+ startOwn: () => Object.fromEntries(stateFields.map((field) => [field.name, startValueOf(field)])),
69
+ };
70
+ }
71
+ return behaviors.length ? behaviors : null;
72
+ }
package/characters.js CHANGED
@@ -8,7 +8,7 @@ import { refuse } from "./declare.js";
8
8
 
9
9
  const BODY_KINDS = ["kinematic", "dynamic"];
10
10
  /** The fields every character shares whatever its kind: a kind's own fields take other names. */
11
- export const CHARACTER_BASE_FIELD_NAMES = ["x", "y", "z", "velocityX", "velocityY", "velocityZ", "facingYawRad", "isGrounded", "airTickCount", "rideBodyNumber", "seatIndex", "layerNumber"];
11
+ export const CHARACTER_BASE_FIELD_NAMES = ["x", "y", "z", "velocityX", "velocityY", "velocityZ", "facingYawRad", "isGrounded", "airTickCount", "rideBodyNumber", "seatIndex", "layerNumber", "sizeNumber"];
12
12
  const KIND_KEYS = ["name", "bodyKind", "stateFields", "inputFields", "step", "stepRiding", "vehicleControls", "isSteppedBeforeWorld", "canPushBodies"];
13
13
  /** What a piece built on physics may give too: hooks into the world's step, and calls of its own. */
14
14
  const EXTENSION_KEYS = ["startKindState", "beforeWorldStep", "afterWorldStep", "onBodyRemoved", "onCharacterAdded", "onCharacterRemoved", "canRest", "isResting", "onTuning", "drawnWith", "settings", "settingsStatement", "syncedSettingNames", "tuning", "calls", "serverCalls", "drawnCharacter", "startOwn", "readOwn", "writeOwn"];
@@ -19,7 +19,7 @@ const NAME_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
19
19
  const isPlainObject = (given) => given !== null && typeof given === "object" && !Array.isArray(given);
20
20
 
21
21
  /** A field's value when nothing's said: its default, or what its kind starts at. */
22
- function startValueOf(field) {
22
+ export function startValueOf(field) {
23
23
  if (field.defaultValue !== undefined) return field.valueKind === "rotation" ? { ...field.defaultValue } : field.defaultValue;
24
24
  if (field.valueKind === "boolean" || field.valueKind === "press") return false;
25
25
  if (field.valueKind === "choice") return field.choices[0];
@@ -43,10 +43,13 @@ export function stickVehicleControls(input) {
43
43
  * cooldowns), as @zaisma/net's fields: shared on the wire, so every side steps from the same.
44
44
  * - inputFields: what moves it, as @zaisma/net's input fields.
45
45
  * - step(character, input, stepContext): one fixed step of one character. character has id, own (the kind's fields,
46
- * change them in place), velocity { x, y, z } (a kinematic one's), facingYawRad, isGrounded, airTickCount, and
47
- * rigidBody and collider (the engine's). stepContext has moveAndSlide(character, movedM, into), castRay, castBall,
48
- * overlapBall, bodyState(bodyId), characterState(characterId), setJoint(jointId, { isEnabled }),
49
- * setLayer(character, collisionLayerName), tickDurationSec, tuning (the world's numbers), isInCharge, isReplay and emit.
46
+ * change them in place), velocity { x, y, z } (a kinematic one's), facingYawRad, isGrounded, airTickCount,
47
+ * characterSizeName (which of the world's characterSizes it is, null for the world's own) and rigidBody and collider
48
+ * (the engine's). stepContext has moveAndSlide(character, movedM, into), castRay, castBall, overlapBall,
49
+ * bodyState(bodyId), characterState(characterId), setJoint(jointId, { isEnabled }), setLayer(character,
50
+ * collisionLayerName), setSize(character, characterSizeName) (a crouch; false where the size has no room),
51
+ * isRestingOnLevel(character) (it stands on what never moves and touches nothing else: with nothing asked of it and
52
+ * no speed, a step would leave it where it is, and the kind may return before its move), tickDurationSec, tuning (the world's numbers), isInCharge, isReplay and emit.
50
53
  * A field with isShared: false is the kind's own memory in each game, never sent nor compared: set by each step
51
54
  * afresh, read by drawnCharacter and characterState (sprinting, stopped at deep water). It isn't put back on a replay.
52
55
  * - stepRiding(character, input, stepContext): one fixed step of a character sitting in a seat, to keep its own fields
@@ -115,6 +118,8 @@ const TURN_SPEED_RAD_PER_SEC = 12;
115
118
  const COYOTE_TICK_COUNT = 4;
116
119
  /** How much faster running is than walking. */
117
120
  const RUN_SPEED_PCT = 180;
121
+ /** How quickly a walker's legs answer what slows it (a zone's dampingNumber): it wades at 1 / (1 + dampingNumber x this) of its speed. */
122
+ const WADE_RESPONSE_SEC = 0.25;
118
123
 
119
124
  /**
120
125
  * Where the player pushes, in the world, from a stick and where they look: moveY forward along the view, moveX to
@@ -162,11 +167,18 @@ export function walkingCharacters() {
162
167
  export function walkStep(character, input, stepContext) {
163
168
  const { tickDurationSec, tuning } = stepContext;
164
169
  const wish = wishOf(input, stepWish);
165
- const speedMPerSec = tuning.walkSpeedMPerSec * (input.isRunning ? RUN_SPEED_PCT / 100 : 1);
166
170
  const velocity = character.velocity;
171
+ // What the zones it stands in do to it: their pull, push and slowing (wind, water, a room without gravity).
172
+ const zoneEffects = stepContext.zoneEffectsOf?.(character) ?? null;
173
+ // Its legs work against what slows it: it wades at a share of its speed, the same at any step rate.
174
+ const speedMPerSec = (tuning.walkSpeedMPerSec * (input.isRunning ? RUN_SPEED_PCT / 100 : 1)) / (1 + (zoneEffects?.dampingNumber ?? 0) * WADE_RESPONSE_SEC);
175
+ // Standing still on what never moves, with nothing asked: this step would leave it exactly here, so it's skipped,
176
+ // and a crowd standing about costs nothing.
177
+ if (!zoneEffects && wish.lengthNumber === 0 && !input.jump && character.isGrounded && velocity.x === 0 && velocity.y === 0 && velocity.z === 0 && stepContext.isRestingOnLevel?.(character)) return;
167
178
  const accelerationMPerSecPerSec = character.isGrounded ? GROUND_ACCELERATION_M_PER_SEC_PER_SEC : AIR_ACCELERATION_M_PER_SEC_PER_SEC;
168
179
  // In the air with nothing asked, a walker keeps the speed it left the ground with.
169
- if (character.isGrounded || wish.lengthNumber > 0.01) {
180
+ const isWalking = character.isGrounded || wish.lengthNumber > 0.01;
181
+ if (isWalking) {
170
182
  const missingX = wish.x * speedMPerSec - velocity.x;
171
183
  const missingZ = wish.z * speedMPerSec - velocity.z;
172
184
  const missingMPerSec = Math.hypot(missingX, missingZ);
@@ -177,7 +189,15 @@ export function walkStep(character, input, stepContext) {
177
189
  if (input.jump && character.airTickCount <= COYOTE_TICK_COUNT && velocity.y <= tuning.jumpSpeedMPerSec * 0.5) {
178
190
  velocity.y = tuning.jumpSpeedMPerSec;
179
191
  character.airTickCount = COYOTE_TICK_COUNT + 1;
180
- } else velocity.y -= tuning.gravityMPerSecPerSec * tickDurationSec;
192
+ } else velocity.y -= ((tuning.gravityMPerSecPerSec * (zoneEffects?.gravityPct ?? 100)) / 100) * tickDurationSec;
193
+ if (zoneEffects) {
194
+ // What its legs don't drive (its fall, and its drift through the air) is slowed as a body's is.
195
+ const slowedNumber = 1 / (1 + zoneEffects.dampingNumber * tickDurationSec);
196
+ const driftSlowedNumber = isWalking ? 1 : slowedNumber;
197
+ velocity.x = (velocity.x + zoneEffects.pushMPerSecPerSec.x * tickDurationSec) * driftSlowedNumber;
198
+ velocity.y = (velocity.y + zoneEffects.pushMPerSecPerSec.y * tickDurationSec) * slowedNumber;
199
+ velocity.z = (velocity.z + zoneEffects.pushMPerSecPerSec.z * tickDurationSec) * driftSlowedNumber;
200
+ }
181
201
  stepDesiredM.x = velocity.x * tickDurationSec;
182
202
  stepDesiredM.y = velocity.y * tickDurationSec;
183
203
  stepDesiredM.z = velocity.z * tickDurationSec;