UNITY3D物理引擎Rigidbody,Collider,PhysicMaterial的整理

其中最基本的关系:
Collider是最基本的触发物理的条件,例如碰撞检测。基本上,没有Collider物理系统基本没有意义(除了重力)。

Rigidbody是物体的基本物理属性设置,当检测碰撞完之后,就要计算物理效果,而Rigidbody就是提供计算基本参数的玩意。

PhysicMaterial则是附加的基本物理参数,是一个物理材质,UNITY3D有自带默认的物理材质的系数(在Edit/Project Settings/Physic下设置),它参与碰撞的计算例如反弹效果摩擦效果等。

Rigidbody部分:

Rigidbody组件的中文手册:http://game.ceeger.com/Script/Rigidbody/Rigidbody.html

Rigidbody相关具体函数我就不解释了,看官方手册就很明朗,不过有几个还是要讲一下。
1.
如果没有Rigidbody而设置了Collider碰撞的话,那这个物体就是个死死不会动的物体。
假设有Rigidbody去撞它的话,那将会被弹开。不过,假设该脚本控制的是位移而不是物理加力的方式的话,将穿透过去。
两个没有Rigidbody的物体,也是穿透。
两个只有collider而没有rigidbody啥都不会发生,碰撞时连OnTriggerEnter等函数也不会触发。
若碰撞体设置了isTrigger属性,将取代UNITY的物理函数来运算。可以在触发函数里将其屏蔽,再次触发碰撞等效果。

2.
如果物理系统感觉不真实不好,那很可能是缩放的问题。如果你的游戏世界非常大,所以的东西将显示移动非常慢,确保你所有的模型为真实世界大小。例如,一个汽车应该有4米长,一个角色约2米高。物体以相同的加速度下落,不论大或小,重或轻。如果你的游戏世界有较大的缩放,物体仍以相同的加速度下落,但是因为所有的物体都比较大,物体的下落显得就比较慢。(BY U3D圣典的翻译)

3.
当改变刚体参数的时候(例如质量等),应该在FixedUpdate函数中使用它,物理模拟以离散的时间步执行。FixedUpdate函数在每一步之前被立即调用。(修改自U3D圣典的翻译)

4.
isKinematic这个参数指的是是否受物理力的影响,如果勾上则不收AddForce等物理添加力的函数影响了。

5.
collisionDetectionMode 碰撞检测模式
使用这个创建一个刚体的连续碰撞检测,从没有碰撞检测的其他物体传递,用来防止快速移动的物体,为了获得最佳效果,为快速移动的物体设置这个值为CollisionDetectionMode.ContinuousDynamic,以及为其他与之需要碰撞的物体设置这个值,为CollisionDetectionMode.Continuous。这个对物理性能有很大影响,所以只要给它设置为默认值 CollisionDetectionMode.Discrete,假如快速物体的碰撞没有任何问题。连续碰撞检测只支持刚体的球体、胶囊或盒子碰撞器。(BY U3D圣典的翻译)

6.
AddTorque()
添加一个让物体旋转的力——力矩。
参照百度百科:http://baike.baidu.com/view/36869.htm


7.
关于爆炸和聚拢。
AddForceAtPosition()提供一个聚拢的力
AddExplosionForce()可用于炸弹爆炸的效果
ClosestPointOnBounds()可以计算范围内从内到外的伤害,可以计算爆炸范围内不同地点受到的伤害。好东西。

8.
与collider相应的时间触发
OnCollisionEnter/OnCollisionExit/OnCollisionStay

9.
当collider的isTrigger属性为true的时候,其碰撞事件将转移到自定义脚本那。若想两方同时触发,再加个碰撞体来检测。或者直接触发完后将isTrigger设为false,则会再触发rigidbody的碰撞。


Collider部分:
Collider倒没啥好讲的,主要就是一个isTrigger属性。还有选用怎么样的Collider,选用的话看情况而定了。
其中物理材质在下面提一下,这个对于物理效果来说还是挺重要的。

两Collider相碰,至少要有一个物体具有Rigibody刚体才会触发Trigger函数。

当物体进来,OnTriggerEnter当然会触发。出去时,OnTriggerExit也当然触发。那么物体在进来后Destory后会如何?经过测试是:不会调用OnTriggerExit。

不仅是OnTriggerEnter,OnCollisionEnter这个由碰撞引起的函数也很有用,具体以项目所用为标准把,多查查函数手册。

PhysicMaterial部分:

PhysicMaterial的各属性手册:http://game.ceeger.com/Script/PhysicMaterial/PhysicMaterial.html

一般来说只用前三个吧。
1.dynamicFriction
移动时候使用的摩擦力。这个值在0到1之间。
2.staticFriction
当物体在表面静止时使用的摩擦力。通常在0到1之间。
3.bounciness
表面的弹力怎样?0值没有弹力。1值没有能量损失的反弹。

设置好材质直接用就可以了,拖到collider里面。

以下是参数介绍:

Rigidbody 刚体

Inherits from Component

Control of an object's position through physics simulation.

通过物理模拟控制一个物体的位置。

Rigidbody components take control over an object's position - it makes the objects fall down under the influence of gravity, and can calculate how objects will respond to collisions.

Rigidbody组件控制物体的位置 - 它使物体在重力影响下下落,并可计算物体将怎样响应碰撞。

When manipulating rigidbody parameters you should work inside the FixedUpdate function. Physics simulation is carried out in discrete timesteps. TheFixedUpdate function is called immediately before each step.

当操作刚体参数的时候,你应该在FixedUpdate函数中使用它,物理模拟以离散的时间步执行。FixedUpdate函数在每一步之前被立即调用。

Things to watch out for when using rigid bodies:

使用刚体需要注意的事:

1. If your simulation looks like slow motion and not solid: This is a problem of scale. When your game world is huge everything will appear to be move very slowly. Make sure all your models are in real world sizes. For example a car should be around 4 meters long. A character around 2 meters high. An object falls at the same acceleration no matter big or small, heavy or light. If your game world has a large scale, objects will still fall at the same acceleration. But since everything is larger, objects will appear like they fall slower.

如果你的模拟看起来像慢动作并且不真实: 这是缩放的问题。如果你的游戏世界非常大,所以的东西将显示移动非常慢,确保你所有的模型为真实世界大小。例如,一个汽车应该有4米长,一个角色约2米高。物体以相同的加速度下落,不论大或小,重或轻。如果你的游戏世界有较大的缩放,物体仍以相同的加速度下落,但是因为所有的物体都比较大,物体的下落显得就比较慢。

Variables变量

  • The velocity vector of the rigidbody.
    刚体的速度向量。
  • The angular velocity vector of the rigidbody.
    刚体的角速度向量。
  • The drag of the object.
    物体的阻力。
  • The angular drag of the object.
    物体的角阻力。
  • The mass of the rigidbody.
    刚体的质量。
  • Controls whether gravity affects this rigidbody.
    控制重力是否影响整个刚体。
  • Controls whether physics affects the rigidbody.
    控制物理学是否够影响这个刚体。
  • Controls whether physics will change the rotation of the object.
    控制物理是否改变物体的旋转。
  • The Rigidbody's collision detection mode.
    刚体的碰撞检测模式。
  • The center of mass relative to the transform's origin.
    相对于变换原点的质量中心。
  • The center of mass of the rigidbody in world space (Read Only).
    在世界坐标空间的刚体的质量中心。(只读)
  • The rotation of the inertia tensor.
    惯性张量的旋转。
  • The diagonal inertia tensor of mass relative to the center of mass.
    相对于重心的质量的惯性张量对角线。
  • Should collision detection be enabled? (By default always enabled)
    碰撞检测应否启用?(默认总是启用的)
  • Force cone friction to be used for this rigidbody.
    用于该刚体的锥形摩擦力。
  • The position of the rigidbody.
    该刚体的位置。
  • The rotation of the rigdibody.
    该刚体的旋转。
  • Interpolation allows you to smooth out the effect of running physics at a fixed frame rate.
    插值允许你以固定的帧率平滑物理运行效果。
  • Allows you to override the solver iteration count per rigidbody.
    允许你覆盖每个刚体的求解迭代次数。
  • The linear velocity, below which objects start going to sleep. (Default 0.14) range { 0, infinity }
    线性速度,低于该值的物体将开始休眠。(默认0.14)范围{0, infinity}
  • The angular velocity, below which objects start going to sleep. (Default 0.14) range { 0, infinity }
    角速度,低于该值的物体将开始休眠。(默认0.14)范围{0, infinity}
  • The maximimum angular velocity of the rigidbody. (Default 7) range { 0, infinity }
    刚体的最大角速度,(默认7)范围{0, infinity}

Functions函数

  • Sets the mass based on the attached colliders assuming a constant density.
    基于附加的碰撞器假设一个固定的密度设置质量。
  • Adds a force to the rigidbody. As a result the rigidbody will start moving.
    添加一个力到刚体。作为结果刚体将开始移动。
  • Adds a force to the rigidbody relative to its coordinate system.
    添加一个力到刚体。相对于它的系统坐标。
  • Adds a torque to the rigidbody.
    添加一个力矩到刚体。
  • Adds a torque to the rigidbody relative to the rigidbodie's own coordinate system.
    添加一个力矩到刚体,相对于刚体自身的坐标系统。
  • Applies force at position. As a result this will apply a torque and force on the object.
    在position位置应用force力。作为结果这个将在这个物体上应用一个力矩和力。
  • Applies a force to the rigidbody that simulates explosion effects. The explosion force will fall off linearly with distance to the rigidbody.
    应用一个力到刚体来模拟爆炸效果。爆炸力将随着到刚体的距离线形衰减。
  • The closest point to the bounding box of the attached colliders.
    到附加的碰撞器边界框上的最近点。
  • The velocity relative to the rigidbody at the point relativePoint.
    相对于刚体在relativePoint点的速度。
  • The velocity of the rigidbody at the point worldPoint in global space.
    刚体在世界坐标空间中worldPoint点的速度。
  • Moves the rigidbody to position.
    移动刚体到position。
  • Rotates the rigidbody to rotation.
    旋转刚体到rot。
  • Forces a rigidbody to sleep at least one frame.
    强制一个刚体休眠至少一帧。
  • Is the rigidbody sleeping?
    刚体在休眠么?
  • Forces a rigidbody to wake up.
    强制唤醒一个刚体。
  • Tests if a rigidbody would collide with anything, if it was moved through the scene.
    如果一个刚体碰到任何东西触发测试,如果它是穿过场景。
  • Like Rigidbody.SweepTest, but returns all hits.
    Rigidbody.SweepTest,但是返回所有碰撞点。

Messages Sent发送消息

  • OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
    当这个collider/rigidbody已经开始接触另一个rigidbody/collider时,OnCollisionEnter被调用。
  • OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
    当这个collider/rigidbody停止接触另一个rigidbody/collider时,OnCollisionExit被调用。
  • OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
    对于每个collider/rigidbody接触另一个rigidbody/collider时,OnCollisionStay每帧被调用一次。

Inherited members继承成员

Inherited Variables继承变量

  • The name of the object. //物体的名字
  • Should the object be hidden, saved with the scene or modifiable by the user?
    物体是否被隐藏、保存在场景中或被用户修改?

Inherited Functions继承函数

  • Returns the instance id of the object.
    返回物体的实例ID
  • Returns the name of the game object.
    返回游戏物体的名称。

Inherited Class Functions继承类函数

  • Does the object exist?
    物体是否存在?
  • Clones the object original and returns the clone.
    克隆原始物体,并返回克隆的物体
  •  
  • Removes a gameobject, component or asset.
    删除一个游戏物体、组件或资源
  • Destroys the object obj immediately. It is strongly recommended to use Destroy instead.
    立即销毁物体obj,强烈建议使用Destroy代替。
  • Returns a list of all active loaded objects of Type type.
    返回Type类型的所有激活的加载的物体列表
  • Returns the first active loaded object of Type type.
    返回Type类型第一个激活的加载的物体。
  • Compares if two objects refer to the same
    比较如果两个物体相同
  • Compares if two objects refer to a different object
    比较如果两个物体不同
  • Makes the object target not be destroyed automatically when loading a new scene.
    加载新场景的时候使目标物体不被自动销毁。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值