Read this manual in English

# 處理动画碰撞

function on_message(self, message_id, message, sender)
-- 处理碰撞
if message_id == hash("contact_point_response") then
local newpos = go.get_position() + message.normal * message.distance
go.set_position(newpos)
end
end • 根据 A 的穿透距离把角色向上移 (黑色箭头)
• 根据 B 的穿透距离把角色向左上移 (黑色箭头) $l = vmath.project(A, B) \times vmath.length(B)$

1. 把当前矫正向量映射到碰撞穿透向量上.
2. 计算穿透向量的补偿 (按照上述公式).
3. 依照补偿向量移动对象.
4. 把补偿向量累加到矫正向量中.

function init(self)
-- 校正向量
self.correction = vmath.vector3()
end

function update(self, dt)
-- 重置矫正向量
self.correction = vmath.vector3()
end

function on_message(self, message_id, message, sender)
-- 处理碰撞
if message_id == hash("contact_point_response") then
-- 获取位移计算所需数据.
-- 当前帧可能有多个碰撞点需要处理,
-- 通过累积矫正向量,
-- 达到正确计算位移的目的:
if message.distance > 0 then
-- 第一步, 把矫正向量投射到
-- 穿透向量上.
local proj = vmath.project(self.correction, message.normal * message.distance)
if proj < 1 then
-- 没有过冲的才需要补偿.
local comp = (message.distance - message.distance * proj) * message.normal
-- 应用补偿向量.
go.set_position(go.get_position() + comp)
-- 积累矫正向量.
self.correction = self.correction + comp
end
end
end
end


Did you spot an error or do you have a suggestion? Please let us know on GitHub!
{"ft_lang_label":"__label__zh","ft_lang_prob":0.6494959,"math_prob":0.8703952,"size":1469,"snap":"2022-40-2023-06","text_gpt3_token_len":819,"char_repetition_ratio":0.14266212,"word_repetition_ratio":0.09836066,"special_character_ratio":0.25799865,"punctuation_ratio":0.27203065,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97690684,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,6,null,6,null,6,null,6,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-06T10:01:12Z\",\"WARC-Record-ID\":\"<urn:uuid:52b2a364-aae1-46c7-942f-2682e6cc0d13>\",\"Content-Length\":\"54951\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ae2255f5-16d9-4d3b-a523-696a75e76bce>\",\"WARC-Concurrent-To\":\"<urn:uuid:180af645-569b-4baf-8704-ef78d5e876e1>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://defold.com/zh/manuals/physics-resolving-collisions/\",\"WARC-Payload-Digest\":\"sha1:36NLDSOYPJ5LJVQC3JMUIWY2QQXDWPUX\",\"WARC-Block-Digest\":\"sha1:LHHCRNIVU4MBZL27A2SVZDMQ4QM4VPAY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337803.86_warc_CC-MAIN-20221006092601-20221006122601-00491.warc.gz\"}"}