中文: 這個文章對於Unity Collision.impulse方向問題的研究與結(jié)論 (Unity 2021以前的版本,Unity 2022開始API有ContactPoint.impulse)
English: This article is the research and conclusion about the direction of Unity Collision.impulse (Unity 2021 or before,There is ContactPoint.impulse in API starts from Unity 2022)
中文:
在Unity,以Rigidbody和Collider組合產(chǎn)生的物件發(fā)生碰撞時,兩個碰撞物件雙方會同時收到 OnCollisionEnter(Collision collision) 的訊息
但是,如果印出Collision.impulse的值,會發(fā)現(xiàn)兩個碰撞物件的值是完全相同的,也就是無法知道這個Collision.impulse到底是誰對誰產(chǎn)生的衝力
但是ContactPoint.thisCollider永遠(yuǎn)會是自己,而ContactPoint.otherCollider永遠(yuǎn)會是對方,而ContactPoint.normal會永遠(yuǎn)是對方指向自己的向量
因此如果想得到正確的衝力向量,必須使用ContactPoint.normal
結(jié)論來說
他人對自己造成的衝力: ContactPoint.normal * Collision.impulse.magnitude
自己對他人造成的衝力: ContactPoint.normal * -1f * Collision.impulse.magnitude
English:
For short, Collision.impulse does not guarantee the direction. Both object shares exact same Collision.impulse.
Hence, if you want to get direction information. You should use ContactPoint.normal together.
ContactPoint.normal is the direction from other to self.
To get the impulse applying on self from other, use "ContactPoint.normal * Collision.impulse.magnitude".
To get the impulse applying on other from self, use "ContactPoint.normal * -1f * Collision.impulse.magnitude".