diff --git a/debug/physics/collectionproxy.png b/debug/physics/collectionproxy.png new file mode 100644 index 0000000..440f716 Binary files /dev/null and b/debug/physics/collectionproxy.png differ diff --git a/debug/physics/example.md b/debug/physics/example.md index 75d53e1..8a5a5e1 100644 --- a/debug/physics/example.md +++ b/debug/physics/example.md @@ -3,9 +3,21 @@ tags: debug title: Physics debug brief: This example allows you to toggle physics debug visualization as well as changing the time step so the simulation runs at one tenth of the speed. author: Defold Foundation -scripts: physics.script +scripts: physics.script, loader.script +thumbnail: thumbnail.png --- With the physics visualization on, all collision object shapes are visible. In addition, at intersections the normals at the collision points are shown. -![physics debug](physics.png) \ No newline at end of file +The example collection consists of: +- 4 blocks with dynamic collision objects with Restituion 1.0, so they bounce forever, +- 4 walls with static collision objects forming boundaries for the blocks, +- game object `go` with: + - label with example description, + - a script `physics.script` included below. + +![physics debug](physics.png) + +This collection is additionally loaded via a `Collection Proxy` component in `main.collection`. Therefore, sending message `set_time_step` to its url `"main:/loader#physicsproxy"` is causing the proxy to have a different update time, causing e.g. the slow-motion effect, which might be helpful when debugging physics. + +![collection proxy](collectionproxy.png) \ No newline at end of file diff --git a/debug/physics/example/loader.script b/debug/physics/example/loader.script new file mode 100644 index 0000000..328ad5c --- /dev/null +++ b/debug/physics/example/loader.script @@ -0,0 +1,11 @@ +function init(self) + msg.post(".", "acquire_input_focus") + msg.post("#physicsproxy", "load") +end + +function on_message(self, message_id, message, sender) + if message_id == hash("proxy_loaded") then + msg.post(sender, "init") + msg.post(sender, "enable") + end +end \ No newline at end of file diff --git a/debug/physics/example/main.collection b/debug/physics/example/main.collection new file mode 100644 index 0000000..0f77cf7 --- /dev/null +++ b/debug/physics/example/main.collection @@ -0,0 +1,57 @@ +name: "main" +scale_along_z: 0 +embedded_instances { + id: "loader" + data: "components {\n" + " id: \"loader\"\n" + " component: \"/example/loader.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " property_decls {\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"physicsproxy\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/physics.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/debug/physics/example/physics.script b/debug/physics/example/physics.script index b97793b..6993c64 100644 --- a/debug/physics/example/physics.script +++ b/debug/physics/example/physics.script @@ -7,9 +7,9 @@ function on_input(self, action_id, action) if action_id == hash("touch") and action.pressed then msg.post("@system:", "toggle_physics_debug") -- <3> if self.show_debug then -- <4> - msg.post("main:/loader", "set_time_step", { factor = 1, mode = 0 }) + msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 1, mode = 0 }) else - msg.post("main:/loader", "set_time_step", { factor = 0.1, mode = 1 }) + msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 0.1, mode = 1 }) end self.show_debug = not self.show_debug -- <5> end diff --git a/debug/physics/game.project b/debug/physics/game.project index f80d2b3..05ce945 100644 --- a/debug/physics/game.project +++ b/debug/physics/game.project @@ -3,7 +3,7 @@ title = Defold-examples version = 0.1 [bootstrap] -main_collection = /example/physics.collectionc +main_collection = /example/main.collectionc [input] game_binding = /builtins/input/all.input_bindingc diff --git a/debug/physics/thumbnail.png b/debug/physics/thumbnail.png new file mode 100644 index 0000000..46fd7a4 Binary files /dev/null and b/debug/physics/thumbnail.png differ