Unity's physics system.

物理引擎不允许两个碰撞体积重叠,当检测到碰撞时,会分析物体的速度、旋转和形状来计算碰撞。静态碰撞体通常是场景中不动的部分,如墙壁或地板;而动态碰撞体是可以移动的对象,如玩家角色或车辆。当物体旋转时,Unity会重新计算所有静态碰撞体,这可能会影响性能。使用刚体组件可以标记动态碰撞体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The physics engine does not allow two collider volumes to overlap. When the physics engine detects that any two or more colliders will overlap that frame the physics engine will look at the objects and analyse their speed and rotation and shape and calculate a collision. One of the major factors in this calculation is whether the colliders are static or dynamic. Static colliders are usually non-moving, parts of your scene, like the walls, the floor or the fountain in the courtyard. Dynamic colliders are things that move like the player's sphere or a car. When calculating a collision the static geometry will not be affected by the collision. But the dynamic objects will be. In our case the player's sphere is dynamic, or moving geometry, and it is bouncing off the static geometry of the cubes. Just as it bounces off the static geometry of the walls. 
The physics engine can however allow the penetration or overlap of collider volumes. When it does this the physics engine still calculates the collider volumes and keeps track of the collider overlap. But it doesn't physically act on the overlapping objects, it doesn't cause a collision. We do this by making our colliders in to triggers, or trigger colliders. When we make our colliders in to a trigger, or tigger collider, we can detect the contact with that trigger through the contact with that trigger through the OnTrigger event messages.

As a performance optimisation Unity calculates all the volumes of all the static colliders in a scene and holds this information in a cache. this makes sense as static colliders shouldn't move, and this saves recalculating this information every frame.
Where we have made our mistake is by rotating our cubes. Any time we move, rotate, or scale a static collider Unity will recalculate all the static colliders again and update the static collider cache. To recalculate the cache takes resources.
We can move, rotate or scale dynamic colliders as often as we want and Unity won't recache any collider volumes. Unity expects us to move colliders. We simply need to indicate to Unity which colliders are dynamic before we move them. We do this by using the rigid body component. Any game object with a collider and a rigid body is considered dynamic. Any game object with a collider attached but no physics rigid body is expected to be static.

Standard rigid bodies are moved using physics forces. Kinematic rigid bodies are moved using their transform.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值