角色控制器(CharacterController):
    首先,角色控制器没有碰撞效果,这是和刚体的区别,不像刚体可以给其力
    如果想使人物移动,直接复制官方文本中的CharacterController下的Move()方法,前台添加“CharacterController”这个组件。
    代码:

    1. using UnityEngine;
    2. using System.Collections;
    3. public class NewBehaviourScript : MonoBehaviour {
    4. public float speed = 6.0F;
    5. public float jumpSpeed = 8.0F;
    6. public float gravity = 20.0F;
    7. private Vector3 moveDirection = Vector3.zero;
    8. void Start() {
    9. }
    10. void Update() {
    11. CharacterController controller = GetComponent<CharacterController>();
    12. if (controller.isGrounded) {
    13. moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    14. moveDirection = transform.TransformDirection(moveDirection);
    15. moveDirection *= speed;
    16. if (Input.GetButton("Jump"))
    17. moveDirection.y = jumpSpeed;
    18. }
    19. moveDirection.y -= gravity * Time.deltaTime;
    20. controller.Move(moveDirection * Time.deltaTime);
    21. }
    22. }

    无需理解,直接复制就可以用了,前后左右移动。
    参数:
    Slope Limit爬坡限制:小于等于此角度可以上坡
    Step Offset台阶高度:
    Skin Width 皮肤宽度:太大就抖动,太小就卡住,最好设置成Radius半径的10%
    Min Move Distance:0,太多不行,太小动不了
    Center:中心点坐标
    Radius:半径,一般0.5
    Height:高,一般2.0