角色控制器

The Character Controller is mainly used for third-person or first-person player control that does not make use of Rigidbody physics.

角色控制器主要用於第三人稱或第一人稱遊戲主角控制,並不使用剛體物理效果。


The Character Controller 角色控制器示例

Properties 屬性

  • Height
    高度
    The Character's Capsule Collider height. Changing this will scale the collider along the Y axis in both positive and negative directions.
    角色的膠囊碰撞器高度。改變其大小會使碰撞器在Y軸方向3兩端伸縮。
  • Radius
    半徑
    Length of the Capsule Collider's radius. This is essentially the width of the collider.
    膠囊碰撞器的半徑長度。級碰撞器的寬度。
  • Slope Limit
    坡度限制
    Limits the collider to only climb slopes that are equal to or less than the indicated value.
    限制碰撞器只能爬小於等於該值的斜坡。
  • Step Offset
    臺階高度
    The character will step up a stair only if it is closer to the ground than the indicated value.
    角色可以邁上的最高臺階高度。
  • Min Move Distance
    最小移動距離
    If the character tries to move below the indicated value, it will not move at all. This can be used to reduce jitter. In most situations this value should be left at 0.
    如果角色移動的距離小於該值,那角色就不會移動。這可以避免顫抖現象。大部分情況下該值被設爲0。
  • Skin width
    皮膚厚度
    Two colliders can penetrate each other as deep as their Skin Width. Larger Skin Widths reduce jitter. Low Skin Width can cause the character to get stuck. A good setting is to make this value 10% of the Radius.
    皮膚厚度決定了兩個碰撞器可以互相滲入的深度。較大的皮膚厚值度會導致顫抖。小的皮膚厚度值會導致角色被卡住。一個合理的設定是使該值等於半徑(Radius)的10%。
  • Center
    中心
    This will offset the Capsule Collider in world space, and won't affect how the Character pivots.
    該值決定膠囊碰撞器在世界空間中的位置,並不影響角色的行動。

Details 細節

The traditional Doom-style first person controls are not physically   realistic. The character runs 90 miles per hour, comes to a halt   immediately and turns on a dime. Because it is so unrealistic, use of   Rigidbodies and physics to create this behavior is impractical and will   feel wrong. The solution is the specialized Character Controller. It is   simply a capsule shaped Collider which   can be told to move in some direction from a script. The Controller will   then carry out the movement but be constrained by collisions. It will   slide along walls, walk up stairs (if they are lower than the Step Offset) and walk on slopes within the Slope Limit.

傳統的"毀滅戰士"風格的第一人稱控制並未依據物理現實。角色跑到了90英里每小時,然後馬上停下而且可以極快的轉身。因爲是這麼地不真實,用剛體和物理效果來創建這種行爲是不切實際的,感覺上也不對勁。解決辦法就是專門的角色控制器。很簡單,就是一個膠囊碰撞器附加了可以控制其移動的腳本。控制器會執行腳本傳達的動作但被碰撞影響。它會沿着牆動,走上臺階(如果臺階高度低於Step Offset屬性)以及走上坡度小於Slope Limit的斜坡。

The Controller does not react to forces on its own and it does not automatically push Rigidbodies away.

控制器不會對加在它自身上的力做出反應,也不會自動推開其他剛體。

If you want to push Rigidbodies or objects with the   Character Controller, you can apply forces to any object that it   collides with via the OnControllerColliderHit() function through scripting.

如果想讓角色控制器推開其他剛體或者對象,你可以在對象附加的腳本中添加OnControllerColliderHit()函數,這樣對它們施加力就能夠產生碰撞。

On the other hand, if you want your player character to be affected by physics then you might be better off using a Rigidbody instead of the Character Controller.

另外,如果你想讓你的遊戲角色被物理效果影響,那就最好使用剛體而不是角色控制器。

Fine-tuning your character 仔細調整你的角色

You can modify the Height and Radius   to fit your Character's mesh. It is recommended to always use around 2   meters for a human-like character. You can also modify the Center of the capsule in case your pivot point is not at the exact center of the Character.

你可以修改Height 和Radius的大小來使控制器和你的角色網格匹配。對於人形的角色一直推薦使用大約2米。同樣可以修改膠囊的Center屬性來使轉動中心和角色的中心吻合。

Step Offset can affect this too, make sure that this value is between 0.1 and 0.4 for a 2 meter sized human.

Step Offset屬性也會影響角色,確保對於一個兩米大小的人來說該值介於0.1到0.4之間。

Slope Limit should not   be too small. Often using a value of 90 degrees works best. The   Character Controller will not be able to climb up walls due to the   capsule shape.

Slope Limit不能設的太小,一般使用90度會比較合適。由於是膠囊體,角色控制器不會爬上牆。

Don't get stuck 不要被卡住

The Skin Width is one of the most critical properties to get right when tuning your Character Controller.  If your character gets stuck it is most likely because your Skin Width is too small. The Skin Width will let objects slightly penetrate the Controller but it removes jitter and prevents it from getting stuck.

Skin Width是調整你的角色控制器時最難正確設置的邊界值之一。如果你的角色被卡住了,那最有可能就是因爲該值設的太小。Skin Width會讓其他物體有少許穿透控制器但是能夠避免震顫以及阻止被卡住。

It's good practice to keep your Skin Width at least greater than 0.01 and more than 10% of the Radius.

實踐中比較好的值是至少要大於0.01並且大於Radius的10%。

We recommend keeping Min Move Distance at 0.

推薦把Min Move Distance設爲0.

See the Character Controller script reference here

點擊此處查看角色控制器的腳本參考。

You can download an example project showing pre-setup animated and moving character controllers from the Resources area on our website.

可以從我們網站的Resources處下載示例工程,演示了預設值的可以活動和移動的角色控制器。

Hints 提示

  • Try adjusting your Skin Width if you find your character getting stuck frequently.
    如果發現你的角色頻繁被卡住,嘗試調整Skin Width值。
  • The Character Controller can affect objects using physics if you write your own scripts.
    角色控制器可以使用物理效果影響其他對象,前提是你自己寫了腳本。
  • The Character Controller can not be affected by objects through physics.
    角色控制器不能通過物理效果被其他對象影響。
發佈了19 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章