unity physics相关

1.
With careful positioning and sizing, compound colliders can often approximate the shape of an object quite well
while keeping a low processor overhead. Further flexibility can be gained by having additional colliders on child objects
(eg, boxes can be rotated relative to the local axes of the parent object).When creating a compound collider like this,
there should only be one Rigidbody component, placed on the root object in the hierarchy.
如果通过子object达成组合式碰撞盒,刚体组件只能挂到根object上。
2.
In 3D, you can use Mesh Colliders to match the shape of the object’s mesh exactly.(当组合碰撞盒不好拼时用mesh colliders)
a good general rule is to use mesh colliders for scene geometry and approximate the shape of moving objects using compound primitive colliders.
mesh collider主要用来做场景碰撞盒,游戏中移动的实体应该用组合碰撞盒(其实一个胶囊体碰撞盒也差不多了)
3.
Colliders on an object that does have a Rigidbody are known as dynamic colliders.
Static colliders can interact with dynamic colliders but since they don’t have a Rigidbody, they will not move in response to collisions.
带刚体组件的碰撞体是动态碰撞体,不带是静态碰撞体,静态的可以被碰,但不会动,相当于一堵墙。动态的被碰会动。而如果一个刚体不带碰撞盒,则它不会与其他带碰撞体发生碰撞,简单讲,刚体是一个物体,加碰撞盒是给这个刚体能和其他碰撞盒进行交互,必须2组件都有的物体才能正常进入“物理世界”:没有碰撞盒则无法和其他物体交互,没有刚体的碰撞盒是静态的,算不上一个物理世界的物体,就像大地。
4.
Physics materials:一个physics object在碰撞时由于不同表面属性而不同表现,比如冰面很滑,橡皮很有弹性,这些都可以通过Physics materials设置。
一般每个Collider都有一个Material参数设置Physics materials。
5.
OnCollisionEnter 和 OnTriggerEnter 【需要测试一下rigidbody组件的影响】
Collider发生碰撞时,产生一个碰撞,并且挂在这个碰撞体的脚本的OnCollisionEnter将被调用:OnCollisionEnter (collisionInfo : Collision)
(在这个函数如果你不使用collisionInfo,删去collisionInfo参数以避免不必要的计算。注意,当其中至少一个碰撞盒附加非动力学刚体时碰撞事件才会发送)
如果这个Collider被设置为trigger:勾选Is Trigger,不产生碰撞,只调用OnTriggerEnter (other : Collider)
(注意,当其中至少一个碰撞盒附加刚体时trigger事件才会发送)

With normal, non-trigger collisions, there is an additional detail that at least one of the objects involved
must have a non-kinematic Rigidbody (ie, Is Kinematic must be switched off).
If both objects are kinematic Rigidbodies then OnCollisionEnter, etc, will not be called.
With trigger collisions, this restriction doesn’t apply.
(当其中至少一个碰撞盒附加非动力学刚体时碰撞事件才会发送)

测试发现,不带Rigidbody组件的碰撞盒可以算静态的,碰别人有问题,被碰一动不动;
带Kinematic rigidbody碰撞盒顾名思义必须来自自身的力量才能让它动,比如代码控制,碰别人正常,被碰一动不动(因为这是物理世界的力量)
带关闭Kinematic的rigidbody碰撞盒,物理世界的碰撞盒,也可以代码一起控制,碰别人正常,被碰就动。
官方文档说,不带rigidbody的碰撞体,千万不要让它动,会有问题的的。要动就用挂个Kinematic rigidbody

A Rigidbody component can be switched between normal and kinematic behavior at any time using the IsKinematic property.
(IsKinematic开关可以随时关闭开启,这里有一个重要应用就是“布娃娃系统”,正常行走开启,被抓起来扔出去或遇到剧烈碰撞就关闭
四肢都各自挂rigidbody组件,平时开IsKinematic,正常播动画,被踢飞出去等则关闭IsKinematic,让四肢表现得真实点)

原文地址:https://www.cnblogs.com/Tearix/p/6921944.html