Răsfoiți Sursa

manual for collision events (#381)

* update

* update code sharing in getting-help.md

* Export Compliance

* update on file i/o

* pi / 4

* inputs

* forum url

* read only user

* html5 gamepad

* sdk api update

* update

* image properties

* update editor

* defold sdk update

* animation updates

* animation fix

* run as admin

* update bob

* update about AndroidX support

* software render

* linux-faq.md update

* 4.28.2021 updates

* Basis Universal format

* sound & mesh

* gamepad event mapping

* admob url

* Minor edit to building blocks intro text

* update gamepad & ios

* project settings

* libffi version

* scaling

* image compression

* update gamepads

* increase memory

* caching assets

* update 2021/10/6

* update 2021/10/16
blend-modes.md

* update 2021/11/12

* allow dynamic transforms update

* Bundle update

* update faq

* bullet & bob

* script properties update

* editor-styling

* build server url

* editor templates

* spine extension update

* Fix typo in the "optimizations" word in Chinese docs

* Update to material.md - Constants buffers

* Verify Graphics Calls

* H5 parameters

* OpenJDK downloads

* cn update corresponds to [pull 259](https://github.com/defold/doc/pull/259)

* application security

* porting guidelines

* update for 8f1651f

* cn update for 094bf6f

* cn update for 20fdfc5 & 6263317

* cn update for 7/19/2022

* title

* profiling update

* update editor.md

* update bob.md

* update shortcuts

* update fixed update note

* Update properties.md

* Update material.md

* Updates links

* Update bob help with the latest info

* camera & renderer

* Updated android keystore info zh_cn

* bundling.md release vs debug zh_cn

* update bob.md & gui-clipping.md

* contentless bundle

* consoles update

* model animation link

* gamepad & faq

* remove a camera lib

* font shadow render mode fix

* updates about app-manifest and others

* Update script.md

* includes in shaders

* editor scripts

* material updates

* Added dynamic atlas and texture creation

* fixes for atlas and some others

* update screenshots and add explanations (CN)

* add a line about Dynamic Prototype (CN)

* remove "inline" marks in pics

* de-translate the subtitle "Running the debugger" & images fix

* bundle identifier restrictions

* node properties Enabled and Visible (CN)

* release checklist & slice-9

* Update project-settings.md (CN)

* Update camera.md (CN)

* Update project-settings.md (CN)

* culling of meshes (CN)

* Update project-settings.md (CN)

* gltf model file support (CN)

* updates about factory (CN)

* Update bob.md (CN)

* Update bob.jar help (CN)

* Update about renderer and other things

* Update PS4 development and other things

* Dynamic prototype part of the collection factory.

* sync to atlas.md

* sync to design.md

* sync to gpgs.md

* sync to hot-reload.md

* sync to linux.md

* sync to live-update.md

* sync to lua.md

* sync to networking.md

* sync to physics-shapes.md

* sync to push.md

* sync to test.md

* sync to working-offline.md

* update material.md

* update zerobrane.md

* all done

* Splitting .zip archives in live-update.md

* manual for collision events
COCO 1 an în urmă
părinte
comite
626980fb26
1 a modificat fișierele cu 94 adăugiri și 0 ștergeri
  1. 94 0
      docs/zh/manuals/physics-events.md

+ 94 - 0
docs/zh/manuals/physics-events.md

@@ -0,0 +1,94 @@
+---
+title: Defold 的碰撞事件
+brief: 集中使用 `physics.set_listener()` 进行碰撞监听, 传导碰撞和交互信息到一个指定函数里.
+---
+
+# Defold 物理事件处理
+
+以前, Defold 中的物理交互通过广播消息到所有碰撞对象组件来进行处理. 但是, 从版本 1.6.4 开始, Defold 提供了一个更集中的方法 `physics.set_listener()` 函数. 这个函数让你设置一个自定义监听器来处理所有物理交互, 从而简化代码并提高效率.
+
+## 设置物理世界监听器
+
+要使用这个新方法, 需要使用 `physics.set_listener` 函数. 这个函数的参数是一个回调函数, 物理世界中的所有交互发生时就会调用该函数. 一般语法如下:
+
+```lua
+physics.set_listener(function(self, event, data)
+    -- Event handling logic goes here
+end)
+
+```
+
+## 事件数据结构
+
+每个物理事件提供 `data` 表, 包含了与事件相关的特定信息.
+
+1. **碰撞点 (`contact_point_event`):**
+这是物体发生碰撞发出的碰撞点事件. 该事件常用作碰撞详情的处理, 比如计算冲量或自定义碰撞响应.
+
+   - `applied_impulse`: 碰撞产生的冲量.
+   - `distance`: 碰撞对象间的穿透距离.
+   - `a` 和 `b`: 碰撞涉及的物体, 它们包含:
+     - `position`: 世界位置 (vector3).
+     - `id`: 物体 ID (hash).
+     - `group`: 碰撞组 (hash).
+     - `relative_velocity`: 相对于另一物体的速度 (vector3).
+     - `mass`: 千克质量 (number).
+     - `normal`: 碰撞法线, 从另一物体发出 (vector3).
+
+2. **碰撞事件 (`collision_event`):**
+这是物体发生碰撞时发出的事件. 与碰撞点事件相比, 这是一个更普遍的事件, 非常适合检测碰撞, 而无需有关碰撞点的详细信息.
+
+   - `a` 和 `b`: 碰撞事件中涉及的物体, 它们包含:
+     - `position`: 世界位置 (vector3).
+     - `id`: 物体 ID (hash).
+     - `group`: 碰撞组 (hash).
+
+3. **触发器事件 (`trigger_event`):** 
+这是物体碰撞触发器时发出的事件. 它在游戏中创建对象进入或退出某区域时很有用.
+
+   - `enter`: 碰撞交互进入 (true) 退出 (false).
+   - `a` 和 `b`: 触发器事件中涉及的物体, 它们包含:
+     - `id`: 物体 ID (hash).
+     - `group`: 碰撞组 (hash).
+
+4. **射线响应 (`ray_cast_response`):**
+这是射线的响应事件, 提供了射线碰撞物体的相关信息.
+
+   - `group`: 碰撞物体的碰撞组 (hash).
+   - `request_id`: 射线 id (number).
+   - `position`: 碰撞位置 (vector3).
+   - `fraction`: 发生碰撞时光线长度的百分数 (number).
+   - `normal`: 碰撞点的法线 (vector3).
+   - `id`: 碰撞物体的 id (hash).
+
+5. **射线失败 (`ray_cast_missed`):**
+当射线没有碰撞到任何物体时发送该事件.
+
+   - `request_id`: 碰撞失败的射线 id (number).
+
+## 实例
+
+```lua
+local function physics_world_listener(self, event, data)
+    if event == hash("contact_point_event") then
+        -- 处理碰撞点数据
+        pprint(data)
+    elseif event == hash("collision_event") then
+        -- 处理一般碰撞数据
+        pprint(data)
+    elseif event == hash("trigger_event") then
+        -- 处理触发器碰撞数据
+        pprint(data)
+    elseif event == hash("ray_cast_response") then
+        -- 处理射线碰撞数据
+        pprint(data)
+    elseif event == hash("ray_cast_missed") then
+        -- 处理射线失败数据
+        pprint(data)
+    end
+end
+
+function init(self)
+    physics.set_listener(physics_world_listener)
+end
+```