Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added debug/physics/collectionproxy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions debug/physics/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
11 changes: 11 additions & 0 deletions debug/physics/example/loader.script
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions debug/physics/example/main.collection
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 2 additions & 2 deletions debug/physics/example/physics.script
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion debug/physics/game.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added debug/physics/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.