zoukankan      html  css  js  c++  java
  • Unity 角色控制器 Charactor Controller

    Charactor Controller(角色控制器)

    “ 角色控制器允许你在受制于碰撞的情况下很容易的进行运动,而不用处理刚体。

     角色控制器不受力的影响,仅仅当你调用 Move 函数时才运动。

     然后它将执行运动,但是受制于碰撞。"

                                                  --- From Unity3d 官方文档

    我们通常在人物模型上加上这个组件后,就可以控制模型的移动了

    要注意的一点是:加了角色控制器后,他就不受重力影响

    所以要自己在move函数中处理重力的情况

    即我们要自己出来y轴方向上的速度变化

    Charactor Controller 组件参数

    Slope Limit 爬坡限制:小于等于此角度可以上坡

    Step Offset 台阶高度

    Skin Width 皮肤宽度:太大就抖动,太小就卡住,最好设置成 Radius 半径的10%

    Min Move Distance 最小移动距离:0,太多不行,太小动不了

    Center:中心点坐标

    Radius:半径,一般0.5

    Height:高,一般2.0

    Charactor Controller 测试

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

    运行效果:

    *** |  以上内容仅为学习参考、学习笔记使用  | ***

  • 相关阅读:
    嵌入式实验一:LED灯点亮
    [转] sql中的in与not in,exists与not exists的区别
    订单管理系统基本情况
    solaris系统分区及格式化
    百度超大网盘邀请码,点击可以获得额外的300M哦
    vb设置代理ip
    我看到一种防伪查询系统,叫做西门防伪防伪查询系统,不知道好不好用。
    零碎知识点整理
    初学WCF之消息模式3——双工模式
    HTTP 错误 500.21 Internal Server Error
  • 原文地址:https://www.cnblogs.com/ChenZiRong1999/p/13395132.html
Copyright © 2011-2022 走看看