朱峰社區(qū)首頁(yè) 朱峰社區(qū)

搜索資源 注冊(cè)|登陸

等待

返回 展開菜單
按功能 按軟件

unity3d視頻教程

unity3d視頻教程

包含11節(jié)視頻教程

從零基礎(chǔ)學(xué)習(xí)unity3d游戲引擎,簡(jiǎn)單易學(xué)的視頻教程,讓你快速掌握unity3d,并喜歡上游戲開發(fā)的樂(lè)趣。

關(guān)閉

Unity組件:Character Controller 角色控制器

關(guān)注:1560 留言:0 樓主:黑客小心 發(fā)帖時(shí)間:15年11月16日

黑客小心

普通會(huì)員

黑客小心

社區(qū)兄弟:4級(jí)

四星作品4副五星作品0副

關(guān)注2904人

  • 積分

    106

  • 登陸

    1

  • 發(fā)帖

    7

  • 作品

    4

間隔線


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.
    角色的膠囊碰撞器高度。改變其大小會(huì)使碰撞器在Y軸方向3兩端伸縮。
  • Radius
    半徑
    Length of the Capsule Collider's radius. This is essentially the width of the collider.
    膠囊碰撞器的半徑長(zhǎng)度。級(jí)碰撞器的寬度。
  • Slope Limit
    坡度限制
    Limits the collider to only climb slopes that are equal to or less than the indicated value.
    限制碰撞器只能爬小于等于該值的斜坡。
  • Step Offset
    臺(tái)階高度
    The character will step up a stair only if it is closer to the ground than the indicated value.
    角色可以邁上的最高臺(tái)階高度。
  • Min Move Distance
    最小移動(dòng)距離
    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.
    如果角色移動(dòng)的距離小于該值,那角色就不會(huì)移動(dòng)。這可以避免顫抖現(xiàn)象。大部分情況下該值被設(shè)為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.
    皮膚厚度決定了兩個(gè)碰撞器可以互相滲入的深度。較大的皮膚厚值度會(huì)導(dǎo)致顫抖。小的皮膚厚度值會(huì)導(dǎo)致角色被卡住。一個(gè)合理的設(shè)定是使該值等于半徑(Radius)的10%。
  • Center
    中心
    This will offset the Capsule Collider in world space, and won't affect how the Character pivots.
    該值決定膠囊碰撞器在世界空間中的位置,并不影響角色的行動(dòng)。
Details 細(xì)節(jié)

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.

傳統(tǒng)的"毀滅戰(zhàn)士"風(fēng)格的第一人稱控制并未依據(jù)物理現(xiàn)實(shí)。角色跑到了90英里每小時(shí),然后馬上停下而且可以極快的轉(zhuǎn)身。因?yàn)槭沁@么地不真實(shí),用剛體和物理效果來(lái)創(chuàng)建這種行為是不切實(shí)際的,感覺上也不對(duì)勁。解決辦法就是專門的角色控制器。很簡(jiǎn)單,就是一個(gè)膠囊碰撞器附加了可以控制其移動(dòng)的腳本?刂破鲿(huì)執(zhí)行腳本傳達(dá)的動(dòng)作但被碰撞影響。它會(huì)沿著墻動(dòng),走上臺(tái)階(如果臺(tái)階高度低于Step Offset屬性)以及走上坡度小于Slope Limit的斜坡。

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

控制器不會(huì)對(duì)加在它自身上的力做出反應(yīng),也不會(huì)自動(dòng)推開其他剛體。

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.

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

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 仔細(xì)調(diào)整你的角色

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的大小來(lái)使控制器和你的角色網(wǎng)格匹配。對(duì)于人形的角色一直推薦使用大約2米。同樣可以修改膠囊的Center屬性來(lái)使轉(zhuǎn)動(dòng)中心和角色的中心吻合。

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屬性也會(huì)影響角色,確保對(duì)于一個(gè)兩米大小的人來(lái)說(shuō)該值介于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不能設(shè)的太小,一般使用90度會(huì)比較合適。由于是膠囊體,角色控制器不會(huì)爬上墻。

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是調(diào)整你的角色控制器時(shí)最難正確設(shè)置的邊界值之一。如果你的角色被卡住了,那最有可能就是因?yàn)樵撝翟O(shè)的太小。Skin Width會(huì)讓其他物體有少許穿透控制器但是能夠避免震顫以及阻止被卡住。

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

實(shí)踐中比較好的值是至少要大于0.01并且大于Radius的10%。

We recommend keeping Min Move Distance at 0.

推薦把Min Move Distance設(shè)為0.

See the Character Controller script reference here

點(diǎn)擊此處查看角色控制器的腳本參考。

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

可以從我們網(wǎng)站的Resources處下載示例工程,演示了預(yù)設(shè)值的可以活動(dòng)和移動(dòng)的角色控制器。

Hints 提示
  • Try adjusting your Skin Width if you find your character getting stuck frequently.
    如果發(fā)現(xiàn)你的角色頻繁被卡住,嘗試調(diào)整Skin Width值。
  • The Character Controller can affect objects using physics if you write your own scripts.
    角色控制器可以使用物理效果影響其他對(duì)象,前提是你自己寫了腳本。
  • The Character Controller can not be affected by objects through physics.
    角色控制器不能通過(guò)物理效果被其他對(duì)象影響。

贊0 踩0

未知用戶

2005-2024 朱峰社區(qū) 版權(quán)所有 遼ICP備2021001865號(hào)-1
2005-2024 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號(hào)

回頂部

1.復(fù)制文本發(fā)給您的QQ好友或群、微信等;好友點(diǎn)擊鏈接以后,轉(zhuǎn)發(fā)就成功了。 2.如朋友點(diǎn)擊您的鏈接,您需要需刷新一下才行;同一個(gè)好友僅能點(diǎn)擊一次。
購(gòu)買VIP,觀看所有收費(fèi)教程!