physics

添加Rigidbody,
添加力来移动物体,而不是在脚本中改变Transform的position and rotation来移动物体.

可以通过脚本来改变Is Kinematic的值,以控制物体引擎是否作用于物体,但这会带来性能开销,应谨慎使用。
通常情况下,你不应该通过改变Transform position的值来改变静态碰撞器(无Rigidbody的碰撞器)的位置,因为这会对物理引擎的性能产生

严重影响。
还可以将碰撞器加到子物体上。但Rigidbody应该放在hierarchy的根物体上。
MeshCollider和Polygon Collider 2D会比原型碰撞器在process-intensive方面要大得多,所以谨慎使用它们以保持良好的性能。
正常情况下,meshcollider不能与别的meshcollider发生碰撞(当他们接触时什么也不会发生),可以将两个meshcollider中的任意一方标

记为Convex来解决这个问题。This will generate the collider shape as a "convex hull" which is like the original mesh but with

any undercuts filled in. The benefit of this is that a convex mesh collider can collide with other mesh colliders so you

may be able to use this feature when you have a moving character with a suitable shape.

在3D中,MeshCollider可以完美匹配物体的形状,但是 In 2D, the Polygon Collider 2D will generally not match the shape of the

sprite graphic perfectly but you can refine the shape to any level of detail you like.  


一个优良的通用准则是:对场景集合体(Scene geometry)使用meshcollider,对移动的物体使用混合的原始碰撞器近似匹配物体的形状。

静态碰撞器可以与动态碰撞器(有Rigidbody的碰撞器)相互作用但是由于静态碰撞器没有Rigidbody,所以静态碰撞器将不会响应于碰撞进

行移动(但与静态碰撞器碰撞的动态碰撞器会)。


可以将多个碰撞器加到一个物体上


虽然碰撞时碰撞器的形状不会变形,但我们可以通过Physics Materials来配置摩擦力和弹力。由于历史原因,3D中叫Physic Material(没有

s)而2D中的等效资源叫Physics Material 2D(有s)

在碰撞被检测到的第一个物理更新(physics update)中,OnCollisionEnter被调用,当两个碰撞器之间保持接触时,OnCollisionStay被调

用。当两个碰撞器之间不再接触时,OnCollisionExit被调用(只调用一次)


CharacterController有一个简单的,总是垂直的capsule-shaped collider

Joints
You can attach one rigidbody object to another or to a fixed point in space using a Joint component. Generally, you want a

joint to allow at least some freedom of motion and so Unity provides different Joint components that enforce different

restrictions. For example, a Hinge Joint allows rotation around a specific point and axis while a Spring Joint keeps the

objects apart but lets the distance between them stretch slightly. As usual, the 2D components have 2D at the end of the

name, eg, Hinge Joint 2D.

Joints also have other options that can enabled for specific effects. For example, you can set a joint to break when the

force applied to it exceeds a certain threshold. Some joints also allow a drive force to occur between the connected

objects to set them in motion automatically.

See the reference pages for the Joint classes to read further about their properties.

Character Controllers
The character in a first- or third-person game will often need some collision-based physics so that he doesn't fall through

the floor or walk through walls. Usually, though, the character's acceleration and movement will not be physically

realistic, so he may be able to accelerate, brake and change direction almost instantly without being affected by momentum.

In 3D physics, this type of behaviour can be created using a Character Controller. This component gives the character a

simple, capsule-shaped collider that is always upright. The controller has its own special functions to set the object's

speed and direction but unlike true colliders, a rigidbody is not needed and the momentum effects are not realistic.

A character controller cannot walk through static colliders in a scene, and so will follow floors and be obstructed by

walls. It can push rigidbody objects aside while moving but will not be accelerated by incoming collisions. This means that

you can use the standard 3D colliders to create a scene around which the controller will walk but you are not limited by

realistic physical behaviour on the character itself.

你可能感兴趣的:(physics)