Skip to content

Commit 5c7abf2

Browse files
ericdowIgnisRBX
andauthored
Update creator docs to reflect improved sleep system (#1242)
## Changes Update the creator docs to reflect recent improvements to the sleep system. This [forum post](https://devforum.roblox.com/t/improved-sleep-system-enhancing-accuracy-consistency-and-performance/3587885) details the improvements. ## Checks By submitting your pull request for review, you agree to the following: - [x] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses. - [x] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses. - [x] To the best of my knowledge, all proposed changes are accurate. --------- Co-authored-by: IgnisRBX <[email protected]>
1 parent 2841d9b commit 5c7abf2

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

content/en-us/physics/sleep-system.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,38 @@ Assemblies can be connected together with [mechanical constraints](../physics/me
99

1010
## Sleep states
1111

12-
Each assembly can be in one of three states: [awake](#awake), [sleep‑checking](#sleep-checking), or [sleeping](#sleeping).
12+
Each assembly can be in one of three states: [awake](#awake), [sleeping](#sleeping), or [sleep‑checking](#sleep-checking).
1313

1414
### Awake
1515

16-
An **awake** assembly is moving or accelerating, and is therefore simulated. Assemblies enter this state from situations outlined in [sleep‑checking](#sleep-checking) and [sleeping](#sleeping), as well as [additional wake situations](#additional-wake-situations).
17-
18-
### Sleep-checking
19-
20-
A non-moving assembly that shares a constraint with at least one [awake](#awake) neighboring assembly is put into the **sleep-checking** state and is not simulated. On each worldstep, a sleep-checking assembly checks whether:
21-
22-
- The **position deviation** of a neighboring assembly is greater than the [Neighbor&nbsp;Displacement](#threshold-reference) threshold.
23-
- The product of a neighboring assembly's **acceleration** and current timestep size is greater than the [Neighbor&nbsp;Angular&nbsp;Velocity](#threshold-reference) and/or [Neighbor&nbsp;Linear&nbsp;Velocity](#threshold-reference) threshold.
24-
25-
If either of these conditions is true, or under any of the [additional wake situations](#additional-wake-situations), the sleep-checking assembly enters the [awake](#awake) state.
16+
An **awake** assembly is moving or accelerating, and is therefore simulated. Assemblies enter this state from situations outlined in [sleeping](#sleeping) and [sleep‑checking](#sleep-checking), as well as [additional wake situations](#additional-wake-situations).
2617

2718
### Sleeping
2819

2920
A **sleeping** assembly is neither moving nor accelerating, and is therefore not simulated.
3021

31-
An assembly is determined to be non-moving by checking its **position deviation**, calculated as the maximum deviation from the average position of the point furthest from its center of mass over the most recent set of worldsteps. If this deviation is greater than the [Displacement](#threshold-reference) threshold, the assembly enters the [awake](#awake) state.
22+
An assembly is determined to be non-moving by checking its **linear velocity** and **rotational velocity**. If its linear velocity is less than the [Linear&nbsp;Velocity](#threshold-reference) threshold and its rotational velocity is less than the [Rotational&nbsp;Velocity](#threshold-reference) threshold, the assembly is considered to be non-moving.
3223

33-
In some cases, simply checking for non-movement would cause an assembly to incorrectly enter the sleeping state. For example, if a ball is thrown straight up, its position barely changes for a number of worldsteps as it approaches its maximum height, making it a candidate to sleep and never fall back down. To handle such cases, the engine monitors whether the product of the assembly's acceleration and current timestep size exceeds the [Linear&nbsp;Velocity](#threshold-reference) and/or [Angular&nbsp;Velocity](#threshold-reference) threshold.
24+
In some cases, simply checking for non-movement would cause an assembly to incorrectly enter the sleeping state. For example, if a ball is thrown straight up, its velocity approaches zero as it reaches its maximum height, making it a candidate to sleep and never fall back down. To handle such cases, the engine considers an assembly to be accelerating if its **linear acceleration** or **rotational acceleration** are greater than the [Linear&nbsp;Acceleration](#threshold-reference) and [Rotational&nbsp;Acceleration](#threshold-reference) thresholds, respectively, and will prevent the assembly from falling asleep.
3425

3526
<Alert severity="info">
3627
If an assembly falls asleep when you expect it to remain awake, it's commonly because the assembly is moving too slowly. In addition to automatic checks outlined in [sleep‑checking](#sleep-checking) and [sleeping](#sleeping), you can forcibly wake up an assembly through the conditions outlined in [additional wake situations](#additional-wake-situations).
3728
</Alert>
3829

30+
### Sleep-checking
31+
32+
A non-moving assembly that shares a constraint with at least one [awake](#awake) neighboring assembly is put into the **sleep-checking** state and is not simulated. On each worldstep, a sleep-checking assembly checks whether:
33+
34+
- Its **linear acceleration** is greater than the [Wake&nbsp;Linear&nbsp;Acceleration](#threshold-reference) threshold.
35+
- Its **rotational acceleration** is greater than the [Wake&nbsp;Rotational&nbsp;Acceleration](#threshold-reference) threshold.
36+
- A neighboring assembly's **linear velocity** is greater than the [Neighbor&nbsp;Linear&nbsp;Velocity](#threshold-reference) threshold.
37+
- A neighboring assembly's **rotational velocity** is greater than the [Neighbor&nbsp;Rotational&nbsp;Velocity](#threshold-reference) threshold.
38+
39+
If any of these conditions is true, or under any of the [additional wake situations](#additional-wake-situations), the sleep-checking assembly enters the [awake](#awake) state.
40+
3941
## Threshold reference
4042

41-
The following table provides the various displacement and velocity thresholds used to determine if an assembly is moving or accelerating.
43+
The following table provides the various velocity and acceleration thresholds used to determine if an assembly is moving or accelerating.
4244

4345
<table>
4446
<thead>
@@ -50,43 +52,59 @@ The following table provides the various displacement and velocity thresholds us
5052
</thead>
5153
<tbody>
5254
<tr>
53-
<td>Neighbor Displacement</td>
54-
<td>0.01 studs</td>
55-
<td>[sleep-checking](#sleep-checking) &rang; [awake](#awake)</td>
55+
<td>Linear Velocity</td>
56+
<td>0.33 studs/s</td>
57+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
5658
</tr>
5759
<tr>
58-
<td>Neighbor Linear Velocity</td>
59-
<td>0.2 studs/s</td>
60-
<td>[sleep-checking](#sleep-checking) &rang; [awake](#awake)</td>
60+
<td>Rotational Velocity</td>
61+
<td>0.42 studs/s</td>
62+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
63+
</tr>
64+
<tr>
65+
<td>Linear Acceleration</td>
66+
<td>0.24 studs/s&sup2;</td>
67+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
6168
</tr>
6269
<tr>
63-
<td>Neighbor Angular Velocity</td>
64-
<td>0.2 radians/s</td>
70+
<td>Rotational Acceleration</td>
71+
<td>0.24 studs/s&sup2;</td>
72+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
73+
</tr>
74+
<tr>
75+
<td>Neighbor Linear Velocity</td>
76+
<td>0.48 studs/s</td>
6577
<td>[sleep-checking](#sleep-checking) &rang; [awake](#awake)</td>
6678
</tr>
6779
<tr>
68-
<td>Displacement</td>
69-
<td>0.001 studs</td>
70-
<td>[sleeping](#sleeping) &rang; [awake](#awake)</td>
80+
<td>Neighbor Rotational Velocity</td>
81+
<td>0.59 studs/s</td>
82+
<td>[sleep-checking](#sleep-checking) &rang; [awake](#awake)</td>
7183
</tr>
7284
<tr>
73-
<td>Linear Velocity</td>
74-
<td>0.1 studs/s</td>
75-
<td>[sleeping](#sleeping) &rang; [awake](#awake)</td>
85+
<td>Wake Linear Acceleration</td>
86+
<td>16.9 studs/s&sup2;</td>
87+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
7688
</tr>
7789
<tr>
78-
<td>Angular Velocity</td>
79-
<td>0.1 radians/s</td>
80-
<td>[sleeping](#sleeping) &rang; [awake](#awake)</td>
90+
<td>Wake Rotational Acceleration</td>
91+
<td>16.9 studs/s&sup2;</td>
92+
<td>[awake](#awake) &rang; [sleeping](#sleeping)</td>
8193
</tr>
8294
</tbody>
8395
</table>
8496

97+
Rotational velocity and acceleration thresholds reflect the velocity and acceleration of a point located on the assembly bounding sphere (a sphere that contains all of the parts in an assembly) that moves rigidly with the assembly.
98+
99+
<Alert severity="info">
100+
For a given angular velocity, the rotational velocity of an assembly is proportional to the assembly bounding sphere radius. This means that larger assemblies can rotate at a lower angular velocity without falling asleep.
101+
</Alert>
102+
85103
## Additional wake situations
86104

87105
In addition to situations outlined in [sleep‑checking](#sleep-checking) and [sleeping](#sleeping), an assembly enters the [awake](#awake) state when:
88106

89-
- It collides with another assembly.
107+
- It collides with another assembly moving faster than 1 studs/s.
90108
- Any physics-related property of any `Class.BasePart` within the assembly changes, including:
91109

92110
- `Class.BasePart.Anchored|Anchored`

0 commit comments

Comments
 (0)