From dbf1ea374869cf03946024f79b4a5a46a09b2d83 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 12 Nov 2023 20:22:28 +0800 Subject: [PATCH] Update box2d.md --- docs/modules/box2d.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/modules/box2d.md b/docs/modules/box2d.md index 9349e543..7056c8d1 100644 --- a/docs/modules/box2d.md +++ b/docs/modules/box2d.md @@ -174,4 +174,35 @@ body_a collides with body_b!! 27 vec2(7.996, 0.000) 28 vec2(7.996, 0.000) 29 vec2(7.996, 0.000) +``` + +## Caveats + +You should set the shape of the body first before accessing fixture properties. +```python +class Body: + ... + + # fixture settings + density: float + friction: float + restitution: float + restitution_threshold: float + is_sensor: bool +``` + +```python +import box2d +world = box2d.World() +body = box2d.Body(world) + +body.is_sensor = True # this will raise an error +``` + +The correct usage is: +```python +body = box2d.Body(world) +body.set_box_shape(1, 1) # set shape first + +body.is_sensor = True # OK ``` \ No newline at end of file