浏览代码

Added physics section and note about allow dynamic transforms for physics

Björn Ritzl 5 年之前
父节点
当前提交
34cf1bff68
共有 3 个文件被更改,包括 58 次插入29 次删除
  1. 25 4
      docs/en/en.json
  2. 30 25
      docs/en/manuals/physics.md
  3. 3 0
      docs/en/manuals/project-settings.md

+ 25 - 4
docs/en/en.json

@@ -289,6 +289,10 @@
                         "path": "/manuals/collection-proxy",
                         "name": "Collection proxy"
                     },
+                    {
+                        "path": "/manuals/physics",
+                        "name": "Collision object"
+                    },
                     {
                         "path": "/manuals/camera",
                         "name": "Camera"
@@ -313,10 +317,6 @@
                         "path": "/manuals/particlefx",
                         "name": "Particle FX"
                     },
-                    {
-                        "path": "/manuals/physics",
-                        "name": "Physics"
-                    },
                     {
                         "path": "/manuals/sound",
                         "name": "Sound"
@@ -384,6 +384,27 @@
                     }
                 ]
             },
+            {
+                "name": "PHYSICS",
+                "items": [
+                    {
+                        "path": "/manuals/physics",
+                        "name": "Collision objects"
+                    },
+                    {
+                        "path": "/manuals/physics/#collision-shapes",
+                        "name": "Collision shapes"
+                    },
+                    {
+                        "path": "/manuals/physics/#ray-casts",
+                        "name": "Ray casts"
+                    },
+                    {
+                        "path": "/manuals/physics/#joints",
+                        "name": "Joints"
+                    }
+                ]
+            },
             {
                 "name": "GAME LOGIC",
                 "items": [

+ 30 - 25
docs/en/manuals/physics.md

@@ -131,6 +131,11 @@ The shape will not be drawn in the editor. You can [enable Physics debugging](/m
 :::
 
 
+### Scaling collision shapes
+
+It is possible to let the collision object and its shapes inherit the scale of the game object. Check the [Allow Dynamic Transforms](/manuals/project-settings/#allow-dynamic-transforms) checkbox in the Physics section of *game.project* to enable this. Note that only uniform scaling is supported and that the smallest scale value will be used if the scale isn't uniform.
+
+
 ### Units used by the physics engine simulation
 
 The physics engine simulates Newtonian physics and it is designed to work well with meters, kilograms and seconds (MKS) units. Furthermore, the physics engine is tuned to work well with moving objects of a size in the 0.1 to 10 meters range (static objects can be larger) and by default the engine treats 1 unit (pixel) as 1 meter. This conversion between pixels and meters is convenient on a simulation level, but from a game creation perspective it isn't very useful. With default settings a collision shape with a size of 200 pixels would be treated as having a size of 200 meters which is well outside of the recommended range, at least for a moving object. In general it is required that the physics simulation is scaled for it to work well with the typical size of objects in a game. The scale of the physics simulation can be changed in `game.project` via the [physics scale setting](/manuals/project-settings/#physics). Setting this value to for instance 0.02 would mean that 200 pixels would be treated as a 4 meters. Do note that the gravity (also changed in `game.project`) has to be increased to accommodate for the change in scale.
@@ -216,31 +221,6 @@ In a trigger collision `"collision_response"` messages are sent. In addition, tr
 `enter`
 : `true` if the interaction was an entry into the trigger, `false` if it was an exit. (`boolean`).
 
-## Ray casts
-
-Ray casts are used to read the physics world along a linear ray. To cast a ray into the physics world, you provide a start and end position as well as a set of collision groups to test against.
-
-If the ray hits a physics object you will get information about the object it hit. Rays intersect with dynamic, kinematic and static objects. They do not interact with triggers.
-
-```lua
-function update(self, dt)
-  -- request ray cast
-  local my_start = vmath.vector3(0, 0, 0)
-  local my_end = vmath.vector3(100, 1000, 1000)
-  local my_groups = { hash("my_group1"), hash("my_group2") }
-
-  local result = physics.raycast(my_start, my_end, my_groups)
-  if result then
-      -- act on the hit (see 'ray_cast_response' message for all values)
-      print(result.id)
-  end
-end
-```
-
-::: sidenote
-Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.
-:::
-
 ## Resolving kinematic collisions
 
 Using kinematic collision objects require you to resolve collisions yourself and move the objects as a reaction. A naive implementation of separating two colliding objects looks like this:
@@ -324,6 +304,31 @@ function on_message(self, message_id, message, sender)
 end
 ```
 
+## Ray casts
+
+Ray casts are used to read the physics world along a linear ray. To cast a ray into the physics world, you provide a start and end position as well as a set of collision groups to test against.
+
+If the ray hits a physics object you will get information about the object it hit. Rays intersect with dynamic, kinematic and static objects. They do not interact with triggers.
+
+```lua
+function update(self, dt)
+  -- request ray cast
+  local my_start = vmath.vector3(0, 0, 0)
+  local my_end = vmath.vector3(100, 1000, 1000)
+  local my_groups = { hash("my_group1"), hash("my_group2") }
+
+  local result = physics.raycast(my_start, my_end, my_groups)
+  if result then
+      -- act on the hit (see 'ray_cast_response' message for all values)
+      print(result.id)
+  end
+end
+```
+
+::: sidenote
+Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.
+:::
+
 ## Joints
 
 Defold supports joints for 2D physics. A joint connects two collision objects using some kind of constraint. The supported joint types are:

+ 3 - 0
docs/en/manuals/project-settings.md

@@ -139,6 +139,9 @@ World gravity along z-axis, `0` by default.
 #### Scale
 Tells the physics engine how to scale the physics worlds in relation to the game world for numerical precision, `0.01`--`1.0`. If the value is set to `0.02`, it means that the physics engine will view 50 units as 1 meter ($1 / 0.02$). The default value is `1.0`.
 
+#### Allow Dynamic Transforms
+Check if the physics engine should scale collision objects using the scale of the game objects they belong to.
+
 #### Debug Scale
 How big to draw unit objects in physics, like triads and normals, `30` by default.