Character Controller 角色控制 Physics物理系列之一

Character Controller 角色控制器

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.4版本
参考链接:https://docs.unity3d.com/Manual/class-CharacterController.html

The Character Controller is mainly used for third-person or first-person player control that does not make use of Rigidbody physics.
角色控制器主要用于在不使用刚体物理的前提下的第三人称或第一人称玩家,控制角色的普遍做法。
在这里插入图片描述

Properties Function
Slope Limit Limits the collider to only climb slopes that are less steep (in degrees) 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. This should not be greater than the Character Controller’s height or it will generate an error.
台阶高度 角色只能爬上高于当前地面高度一定范围内(此值)时才会走上楼梯。这应该不大于角色控制器的高度,否则会产生错误
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.
皮肤厚度 两个碰撞体可以互相穿透到和它们的皮肤厚度一样深的地方。较大的皮肤厚度减少抖动。较低的皮肤厚度会导致角色卡住。一个好的设置是使这个值为半径的10%。
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。
Center This will offset the Capsule Collider in world space, and won’t affect how the Character pivots.
中心点 在世界空间这将偏移胶囊碰撞体,但不会影响如何角色的中心点。
Radius Length of the Capsule Collider’s radius. This is essentially the width of the collider.
半径 胶囊碰撞体的半径长度。本质上这就是碰撞体的宽度
Height The Character’s Capsule Collider height. Changing this will scale the collider along the Y axis in both positive and negative directions.
高度 角色胶囊体碰撞体高度。改变这一点将使碰撞体沿Y轴向正反两个方向缩放。

Character Controller 角色控制 Physics物理系列之一_第1张图片

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.
传统的Doom风格的第一人称控制未遵守在真实物理。这个角色以每小时90英里的速度奔跑,突然停了下来,然后在一个转弯处转弯。因为它是如此的不真实,使用刚体和物理来创造这种行为是不切实际的,而且会让人觉得是错误的。解决方案是用专门的角色控制器。它只是一个胶囊形状的碰撞体,可以从脚本设置的某个方向移动。控制器将执行运动,但会受到碰撞体的约束。它会沿着墙壁滑行,爬上楼梯(如果它们台阶够低的话)和在一定坡度范围内的斜坡上行走。

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.
你可以修改高度和半径来适应你的角色的网格。对于类人角色,建议始终使用大约2米。你也可以修改胶囊的中心,以防你的中心点不在角色的模型原点。

Step Offset can affect this too, make sure that this value is between 0.1 and 0.4 for a 2 meter sized human.
台阶高度也会影响这个值,对于2米大小的人,确保这个值在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.
坡度限制不宜过小。通常使用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.
调整角色控制器时,皮肤厚度是最关键的属性之一。如果你的角色卡住了,很可能是因为你的皮肤厚度太小。皮肤厚度将允许对象稍微穿透控制器,但它消除了抖动,防止它卡住。

It’s good practice to keep your Skin Width at least greater than 0.01 and more than 10% of the Radius.
这是一个很好的实践,让你的皮肤厚度至少大于0.01,并且超过半径的10%。

We recommend keeping Min Move Distance at 0.
我们建议保持最小移动距离为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.

Hints

  • Try adjusting your Skin Width if you find your character getting stuck frequently.
    如果你发现你的角色经常被卡住,试着调整你的皮肤厚度。
  • 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.
    角色控制器不受物理对象的影响。
  • Note that changing Character Controller properties in the inspector will recreate the controller in the scene, so any existing Trigger contacts will get lost, and you will not get any OnTriggerEntered messages until the controller is moved again.
    请注意,在检查器中更改角色控制器属性将在场景中重新创建控制器,因此任何现有的触发器关联的都将丢失,在再次移动控制器之前,您不会收到任何OnTriggerEntered消息。
  • The Character Controller’s capsule used in queries such as raycast might shrink by a small factor. Queries therefore could miss in some corner cases, even when they appear to hit the Character Controller’s gizmo.
    在诸如raycast之类的查询中使用角色控制器的胶囊可能会被一个小因子缩小。因此,在某些特殊情况下,查询可能会丢失,即使它们看起来击中了场景中的角色控制器图标。

你可能感兴趣的:(Physics)