Skip to content

Commit 77cae1d

Browse files
authored
Fixed physics debug example and added description regarding collection proxy and slowing time for debugging. (#136)
1 parent d83f720 commit 77cae1d

File tree

7 files changed

+85
-5
lines changed

7 files changed

+85
-5
lines changed

debug/physics/collectionproxy.png

23.4 KB
Loading

debug/physics/example.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ tags: debug
33
title: Physics debug
44
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.
55
author: Defold Foundation
6-
scripts: physics.script
6+
scripts: physics.script, loader.script
7+
thumbnail: thumbnail.png
78
---
89

910
With the physics visualization on, all collision object shapes are visible. In addition, at intersections the normals at the collision points are shown.
1011

11-
![physics debug](physics.png)
12+
The example collection consists of:
13+
- 4 blocks with dynamic collision objects with Restituion 1.0, so they bounce forever,
14+
- 4 walls with static collision objects forming boundaries for the blocks,
15+
- game object `go` with:
16+
- label with example description,
17+
- a script `physics.script` included below.
18+
19+
![physics debug](physics.png)
20+
21+
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.
22+
23+
![collection proxy](collectionproxy.png)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function init(self)
2+
msg.post(".", "acquire_input_focus")
3+
msg.post("#physicsproxy", "load")
4+
end
5+
6+
function on_message(self, message_id, message, sender)
7+
if message_id == hash("proxy_loaded") then
8+
msg.post(sender, "init")
9+
msg.post(sender, "enable")
10+
end
11+
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "main"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "loader"
5+
data: "components {\n"
6+
" id: \"loader\"\n"
7+
" component: \"/example/loader.script\"\n"
8+
" position {\n"
9+
" x: 0.0\n"
10+
" y: 0.0\n"
11+
" z: 0.0\n"
12+
" }\n"
13+
" rotation {\n"
14+
" x: 0.0\n"
15+
" y: 0.0\n"
16+
" z: 0.0\n"
17+
" w: 1.0\n"
18+
" }\n"
19+
" property_decls {\n"
20+
" }\n"
21+
"}\n"
22+
"embedded_components {\n"
23+
" id: \"physicsproxy\"\n"
24+
" type: \"collectionproxy\"\n"
25+
" data: \"collection: \\\"/example/physics.collection\\\"\\n"
26+
"exclude: false\\n"
27+
"\"\n"
28+
" position {\n"
29+
" x: 0.0\n"
30+
" y: 0.0\n"
31+
" z: 0.0\n"
32+
" }\n"
33+
" rotation {\n"
34+
" x: 0.0\n"
35+
" y: 0.0\n"
36+
" z: 0.0\n"
37+
" w: 1.0\n"
38+
" }\n"
39+
"}\n"
40+
""
41+
position {
42+
x: 0.0
43+
y: 0.0
44+
z: 0.0
45+
}
46+
rotation {
47+
x: 0.0
48+
y: 0.0
49+
z: 0.0
50+
w: 1.0
51+
}
52+
scale3 {
53+
x: 1.0
54+
y: 1.0
55+
z: 1.0
56+
}
57+
}

debug/physics/example/physics.script

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function on_input(self, action_id, action)
77
if action_id == hash("touch") and action.pressed then
88
msg.post("@system:", "toggle_physics_debug") -- <3>
99
if self.show_debug then -- <4>
10-
msg.post("main:/loader", "set_time_step", { factor = 1, mode = 0 })
10+
msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 1, mode = 0 })
1111
else
12-
msg.post("main:/loader", "set_time_step", { factor = 0.1, mode = 1 })
12+
msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 0.1, mode = 1 })
1313
end
1414
self.show_debug = not self.show_debug -- <5>
1515
end

debug/physics/game.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title = Defold-examples
33
version = 0.1
44

55
[bootstrap]
6-
main_collection = /example/physics.collectionc
6+
main_collection = /example/main.collectionc
77

88
[input]
99
game_binding = /builtins/input/all.input_bindingc

debug/physics/thumbnail.png

26.6 KB
Loading

0 commit comments

Comments
 (0)