Skip to content

Commit 87e595b

Browse files
committed
wip: physics docs page
1 parent 3ab8236 commit 87e595b

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

docs/guide/physics.mdx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,52 @@ sidebar_position: 999
44

55
# Physics
66

7-
:::info
7+
:::note
88

9-
This page is a work-in-progress.
9+
**Physics entities do not render to the scene by default.**
10+
11+
You can enable the physics debug overlay in the editor to show wireframe representations of colliders and rigidbodies.
12+
13+
![Physics Debug Button](../../static/img/physics-debug-button.png)
1014

1115
:::
16+
17+
Physics entities in Dreamlab are simulated on at most one client (including the server) at a time, with the position and
18+
rotation being synced to all other connected clients. Entities in the `world` [root](./scenes-and-roots.mdx) default to
19+
being simulated on the server. When a client takes authority of an Entity, it will then be responsible for simulating
20+
its physics.
21+
22+
## Colliders
23+
24+
Colliders are static shapes that other physics entities will interact with. Colliders can be either rectangular or
25+
circular in shape, and do not move on their own. They are ideal for walls, floors, obstacles, etc.
26+
27+
## Rigidbodies
28+
29+
Rigidbody entities by themselves don't do anything, you must add one or more Collider entities as children to define the
30+
shape of the rigidbody. This is where the `mass` value of a collider is used.
31+
32+
## Character Controller
33+
34+
The character controller is a special kind of physics entity. Despite having "character" in the name it can be used for
35+
any kinematic (moving) object. These entities are not simulated by the physics engine and must be controlled by scripts.
36+
After setting the position of a character controller, the physics engine will compute and handle collisions and prevent
37+
the character controller from intersecting colliders.
38+
39+
## Collision Events
40+
41+
The physics system will emit `EntityCollision` events when two colliders (including rigidbody colliders and character
42+
controllers) start and stop colliding. The events are fired on both entities involved in the collision and report
43+
information about the collision.
44+
45+
```ts
46+
import { Behavior, EntityCollision } from "@dreamlab/engine";
47+
48+
export default class MyBehavior extends Behavior {
49+
onInitialize(): void {
50+
this.listen(this.entity, EntityCollision, ({ started, other, contactPoint, normal }) => {
51+
// react to collision event
52+
});
53+
}
54+
}
55+
```
3.38 KB
Loading

0 commit comments

Comments
 (0)