關卡設計相關的物理系統

(1)固定關節
Fixed Joints restricts an object’s movement to be dependent upon another object. This is somewhat similar to Parenting but is implemented through physics rather than Transform hierarchy. The best scenarios for using them are when you have objects that you want to easily break apart from each other, or connect two object’s movement without parenting.

固定關節會通過另一個物體來限制本身的運動。但是這是基於物理引擎的而不是簡單的transform限制。他們的行爲像父子關係一樣。
適用情景:物體之間的斷裂可以使用固定關節組件來完成。還有不通過父子關係的運動限制。
下面對其相應屬性進行介紹:
Connected Body Optional reference to the Rigidbody that the joint is dependent upon. If not set, the joint connects to the world.
本物體所連接的目標物體。

Break Force The force that needs to be applied for this joint to break.
破壞力:設置該屬性閾值,如果收到大於閾值的力,物體會和Connectedbody斷裂。

Break Torque The torque that needs to be applied for this joint to break.
破壞力矩:如果扭力大於該值,那麼就會斷裂。

Enable Collision When checked, this enables collisions between bodies connected with a joint.
激活碰撞體:當該屬性激活之後,由關節連接的碰撞體會相互作用。

Enable Preprocessing Disabling preprocessing helps to stabilize impossible-to-fulfil configurations.
開啓預處理:有助於穩定設置。

那麼這個組件有什麼用呢? 有了這個組件可以靈活的進行場景設計。比如場景當中的一些可以破壞物體。以及一個經典的例子:粘性手榴彈。大體邏輯如下:扔出一個炸彈,一旦炸彈碰到敵人,生成Fixed Joint組件,並且將敵人設置爲Connect Body。
注意,該組件需要剛體的配合。

(2)鉸鏈關節Hinge Joint
The Hinge Joint groups together two Rigidbodies, constraining them to move like they are connected by a hinge. It is perfect for doors, but can also be used to model chains, pendulums, etc.
鉸鏈關節連接兩個剛體。可以模擬門、模型連接以及鐘擺等的物理效果。

相關屬性:
Connected Body:Optional reference to the Rigidbody that the joint is dependent upon. If not set, the joint connects to the world.
連接物體。這個不多說了。
Anchor:The position of the axis around which the body swings. The position is defined in local space.
錨點。注意這個錨點位置參照的是局部空間。這個位置是物體所繞軸的位置。
Axis: The direction of the axis around which the body swings. The direction is defined in local space.
軸。這裏定義了物體圍繞旋轉的軸向。如果模擬門的話(0, 1, 0)是一個不錯的選擇。
Auto Configure Connected Anchor: If this is enabled, then the Connected Anchor position will be calculated automatically to match the global position of the anchor property. This is the default behavior. If this is disabled, you can configure the position of the connected anchor manually.
自動設置連接點:該flag默認爲true,自動計算連接的錨點,注意該錨點爲全局座標系的。如果關掉它,你也可以手動去設置鏈接錨點的位置。
Connected Anchor:Manual configuration of the connected anchor position.
鏈接錨點:手動設置錨點位置。再次強調,這個是全局錨點。
Use Spring Spring makes the Rigidbody reach for a specific angle compared to its connected body.
使用彈簧:這個讓剛體到達一個目標角度。比如該屬性可以充分模擬一個彈簧跳板。
Spring Properties of the Spring that are used if Use Spring is enabled.下面是該模塊的屬性
Spring The force the object asserts to move into the position.
彈簧力:增加到物體的彈簧力。一旦物體偏離目標位置,就會彈回來。
Damper The higher this value, the more the object will slow down.
阻尼:這個值越大,物體的彈性感覺就會越差。
Target Position Target angle of the spring. The spring pulls towards this angle measured in degrees.
目標位置:設置物體目標的目標位置。如果偏移,物體會繼續回到這個位置。

Use Motor The motor makes the object spin around.
馬達系統。可以用這個來模擬一些動態的場景。比如磨坊的大風車。
Motor Properties of the Motor that are used if Use Motor is enabled.
Target Velocity The speed the object tries to attain.
目標速度。
Force The force applied in order to attain the speed.
力:一旦達到目標速度,力的作用就不是很大了。
Free Spin: If enabled, the motor is never used to brake the spinning, only accelerate it.
如果啓用這個標誌位,那麼馬達就會沒有限制,無限加速。

Use Limits If enabled, the angle of the hinge will be restricted within the Min & Max values.
啓用限制:如果啓用,鉸鏈的角度就會被最大值和最小值限制。比如門開關是有角度的。
Limits 所有的相關標誌位。
Min The lowest angle the rotation can go.
最小的角度。
Max The highest angle the rotation can go.
最大的角度。
Bounciness How much the object bounces when it hits the minimum or maximum stop limit.
彈力:如果物體碰觸到最大值和最小值的底線,那麼就會對其施加彈力。
Contact Distance:Within the contact distance from the limit contacts will persist in order to avoid jitter.
Break Force:The force that needs to be applied for this joint to break.
斷裂的力:如果超過相關的力,關節會斷裂。比如炸彈把門炸飛。
Break Torque: The torque that needs to be applied for this joint to break.
斷裂的力矩:如果應用了扭曲力,那麼關節也會斷裂。
Enable Collision When checked, this enables collisions between bodies connected with a joint.
開啓碰撞:鏈接兩個物體碰撞體互相影響。
Enable Preprocessing Disabling preprocessing helps to stabilize impossible-to-fulfil configurations.

(3)Spring Joint 彈簧關節
The Spring Joint joins two Rigidbodies together but allows the distance between them to change as though they were connected by a spring.
彈簧關節加入兩個剛體。可以通過在物體之間鏈接一個彈簧來改變他們之間的距離。

Connected Body The Rigidbody object that the object with the spring joint is connected to. If no object is assigned then the spring will be connected to a fixed point in space.
鏈接物體:這個不多說。和之前都一樣。

Anchor The point in the object’s local space at which the joint is attached.
錨點:注意是局部座標系的錨點。
Auto Configure Connected Anchor: Should Unity calculate the position of the connected anchor point automatically?
自動設置鏈接的錨點:允許unity自動計算全局錨點。
Connected Anchor The point in the connected object’s local space at which the joint is attached.
Spring Strength of the spring.
鏈接錨點:如果上面的Flag沒有設置爲True,可以手動設置全局錨點。
Damper:Amount that the spring is reduced when active.
阻尼:當彈簧激活的情況下影響彈性的情況。
Min Distance Lower limit of the distance range over which the spring will not apply any force.
最小距離:設置彈簧到達的最小程度,在該程度上無法施加任何力。
Max Distance Upper limit of the distance range over which the spring will not apply any force.
最大距離:設置彈簧到達的最大程度,在該程度上無法施加任何力。
Tolerance : Changes error tolerance. Allows the spring to have a different rest length.
容錯率:改變容錯率,允許彈簧在一定程度上有所不同。這樣可以更加真實。
Break Force The force that needs to be applied for this joint to break.
斷裂力:當力達到一定程度,彈簧斷裂。
Break Torque The torque that needs to be applied for this joint to break.
斷裂力矩。
Enable Collision Should the two connected objects register collisions with each other?
是否開啓兩個鏈接物體之間的碰撞檢測。
Enable Preprocessing Disabling preprocessing helps to stabilize impossible-to-fulfil configurations.

注意:
To prevent the spring from oscillating endlessly you can set a Damper value that reduces the spring force in proportion to the relative speed between the two objects. The higher the value, the more quickly the oscillation will die down.
爲了阻止彈簧無限的運動,記得設置一些Damper值,來不斷的減少spring force。這個值越大,彈簧震盪就會越快減慢。這樣可以模擬真實的彈簧特效。

(4)Physic Material 物理材質

The Physic Material is used to adjust friction and bouncing effects of colliding objects.
物理材質用於模擬碰撞體之間的摩擦和彈力。
選擇 Assets > Create > Physic Material來創建物理材質。

Dynamic Friction The friction used when already moving. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it come to rest very quickly unless a lot of force or gravity pushes the object.
動態摩擦力:當在移動過程中所體現出來的摩擦力。0代表的是冰塊一樣的摩擦力。1代表的是非常大的摩擦。
Static Friction :The friction used when an object is laying still on a surface. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it very hard to get the object moving.
靜態摩擦力:在摩擦力用於靜態物體。0代表冰塊。1代表很大的摩擦力。這個代表需要多大的力才能夠推動物體。
Bounciness How bouncy is the surface? A value of 0 will not bounce. A value of 1 will bounce without any loss of energy.
彈性:表面有多少彈性?0代表是沒有彈性,1代表有無能量損失的彈性。
Friction Combine How the friction of two colliding objects is combined.
摩擦結合:兩個物體的摩擦力是如何進行配合的。
- Average The two friction values are averaged. 取值兩個摩擦值的平均。
- Minimum The smallest of the two values is used. 取值兩個摩擦值的最小值。
- Maximum The largest of the two values is used. 取值兩個摩擦值的最大值。
- Multiply The friction values are multiplied with each other.混合值。
Bounce Combine How the bounciness of two colliding objects is combined. It has the same modes as Friction Combine Mode
彈性結合:兩個碰撞體碰撞的彈性融合設置。和摩擦力很像。

注意:
Please note that the friction model used by the Nvidia PhysX engine is tuned for performance and stability of simulation, and does not necessarily present a close approximation of real-world physics. In particular, contact surfaces which are larger than a single point (such as two boxes resting on each other) will be calculated as having two contact points, and will have friction forces twice as big as they would in real world physics. You may want to multiply your friction coefficients by 0.5 to get more realistic results in such a case.

unity使用的是Nvidia PhysX物理引擎,和現實世界的物理還是有一定的差距。舉個例子,兩個BOX互相疊加,而不是單個點接觸。你可以將摩擦力*0.5來模擬出更加真實的效果。

關節和布娃娃的穩定性
接下來是一些關於如何增加穩定性的一些建議。
1.Avoid small Joint angles of Angular Y Limit and Angular Z Limit. Depending on your setup, the minimum angles should be around 5 to 15 degrees in order to be stable. Instead of using a small angle, try setting the angle to zero. This locks the axis and provide a stable simulation.
避免在Y軸和Z軸的關節小角度限制。爲了穩定,最小角度應該設置到5-15度左右。如果不用叫角度,那麼就將最小角度設置爲0。這將會鎖住軸並且提供穩定的模擬。

2.Uncheck the Joint’s Enable Preprocessing property. Disabling preprocessing can help prevent Joints from separating or moving erratically if they are forced into situations where there is no possible way to satisfy the Joint constraints. This can occur if Rigidbody components connected by Joints are pulled apart by static collision geometry (for example, spawning a Ragdoll partially inside a wall).
取消選中關節的啓用預處理屬性。禁止預處理可以幫助防止關節在限制的條件下的不規律移動。總之就是把它關掉吧。並沒啥卵用。
3.Under extreme circumstances (such as spawning partially inside a wall or pushed with a large force), the joint solver is unable to keep the Rigidbody components of a Ragdoll together. This can result in stretching. To handle this, enable projection on the Joints using either ConfigurableJoint.projectionMode or CharacterJoint.enableProjection.
If Rigidbody components connected with Joints are jittering, open the Physics Manager (Edit > Project Settings > Physics) and try increasing the Default Solver Iterations value to between 10 and 20.
在極端情況下(如在大量力量推擠),關節計算器不能夠將布娃娃系統所產生的肢體鏈接限制,這可能導致拉伸。這個BUG在遊戲製作當中很常見。可以使用ConfigurableJoint.projectionMode或CharacterJoint.enableProjection啓用關節上的投影,來解決問題。(在組件上有這個選項)
如果連接有關節的剛體組件抖動,請打開物理管理器(編輯>項目設置>物理),並嘗試將默認解算器迭代值增加到10到20之間。多次迭代有利於更好的模擬物理效果。

If Rigidbody components connected with Joints are not accurately responding to bounces, open the Physics Manager (Edit > Project Settings > Physics) and try increasing the Default Solver Velocity Iterations value to between 10 and 20.
如果和剛體鏈接的關節沒有很快的響應彈性,那麼仍然按照上面的說法增加迭代值,有助於物理系統的更優秀表現。

Never use direct Transform access with Kinematic Rigidbody components connected by Joints to other Rigidbody components. Doing so skips the step where PhysX computes internal velocities of corresponding Rigidbody components, making the solver provide unwanted results. A common example of bad practice is using direct Transform access in 2D projects to flip characters, by altering Transform.TransformDirection on the root boon of the rig. This behaves much better if you use Rigidbody2D.MovePosition and Rigidbody2D.MoveRotation instead.
絕對不要對通過關節鏈接其他剛體的運動學剛體調整Transform。這樣做跳過了PhysX計算相應Rigidbody組件的內部速度的步驟,使得求解器提供了不正確的結果。

Avoid large differences in the masses between Rigidbody components connected by Joints. It’s okay to have one Rigidbody with twice as much mass as another, but when one mass is ten times larger than the other, the simulation can become jittery.
避免由關節連接的兩個物體質量相差過大。兩倍的質量相差沒啥問題。但是如果相差十倍,就很不穩定。

Try to avoid scaling different from 1 in the Transform containing Rigidbody or the Joint. The scaling might not be robust in all cases.
避免讓具有剛體或關節的物體進行縮放,如果他的Scale不是1,會導致不穩定。

If Rigidbody components are overlapping when inserted into the world, and you cannot avoid the overlap, try lowering the Rigidbody.maxDepenetrationVelocity to make the Rigidbody components exit each other more smoothly.
如果剛體在放入世界當中不可避免的導致重疊,嘗試降低Rigidbody.maxDepenetrationVelocity 從而讓兩個剛體離開的更加柔和和真實。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章