角色控制器

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.
    角色控制器不能通过物理效果被其他对象影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值