当前位置:网站首页>Unity CharacterController
Unity CharacterController
2022-07-26 22:43:00 【淡定九号】
Unity CharacterController的使用
引言
CharacterController是Unity自带的组件,常用于第三人称或第一人称角色控制,可以简单的把它看成一个可以指定移动方向的胶囊碰撞体,角色控制器允许您在受碰撞约束的情况下轻松进行移动,而无需处理刚体。
组件

| 属性 | 介绍 |
|---|---|
| Slope Limit | 角色能爬坡的最大角度 |
| Step Offset | 角色能上台阶的最大高度 |
| Skin Width | 两个characterController能够穿透彼此皮肤的最大深度,高的值可以减少抖动,低的值容易让角色卡住,比较好的值是Radius的10%。如果你的角色经常卡住,很可能就是这个值太小了。 |
| Min Move Distance | 最小移动距离,如果移动距离低于这个值,则不会移动。可以较少角色的抖动。 |
| Center | 胶囊碰撞体的中心点 |
| Radius | 胶囊碰撞体的半径(胖瘦) |
| Height | 胶囊碰撞体的高度 |
SimpleMove和Move
区别
Move SimpleMove 官方介绍 Supplies the movement of a GameObject with an attached CharacterController component. Moves the character with speed. 参数 沿y轴的速度被忽略。 速度以米/秒为单位。 重力是自动应用的。 移动时候需要注意乘以时间 重力 重力自动应用 没有重力,需要自己添加 返回值 bool,是否贴地 CollisionFlags,碰撞信息 void Update() { controller.SimpleMove(forward * speed); controller.Move(forward * speed * Time.deltaTime); }建议每帧只调用一次Move或者SimpleMove
物理效果
CharacterController不会受到任何力的影响,也不会对任何物体产生力。
如果想实现物理效果,则可以在下列事件中添加自己想实现的效果
| 事件 | 描述 |
|---|---|
| OnCollisionEnter | collider进入controller时触发 |
| OnCollisionExit | collider从controller内离开时触发 |
| OnCollisionStay | 有Collider停留在controller内时触发 |
| OnTriggerEnter | trigger进入controller时触发 |
| OnTriggerExit | trigger从controller内离开时触发 |
| OnTriggerStay | 有trigger停留在controller内时触发 |
| OnControllerColliderHit | 和其他的controller碰撞时触发 |
private void OnControllerColliderHit(ControllerColliderHit hit)
{
float power = 2.0F;
Rigidbody hitRigidBody = hit.collider.attachedRigidbody;
if (hitRigidBody == null || hitRigidBody.isKinematic)
{
return;
}
//给碰撞物体附加当前速度对应的力
hitRigidBody.AddForce(_Controller.velocity * power);
}
参考资料
【Unity学习笔记】CharacterController组件_一白梦人的博客-CSDN博客_charactercontroller组件
边栏推荐
- c语言实现三子棋游戏
- Are you ready for the Internet of things to revolutionize manufacturing?
- In depth learning report (1)
- 基于485总线的评分系统
- VSCode2015下编译darknet生成darknet.ext时error MSB3721:XXX已退出,返回代码为 1。
- Li Hongyi machine learning (2017 Edition)_ P13: deep learning
- ks 怎么抓salt值?api,did?
- 25 common questions in Flink interview (no answer)
- 梦想的旅程
- Wu Enda's in-depth learning series teaching video learning notes (I) -- logistic regression function for binary classification
猜你喜欢

Website log collection and analysis process

快来:鼓励高校毕业生返乡创业就业,助力乡村振兴

Jenkins--基础--04--安装中文插件
![[CTF attack and defense world] questions about backup in the web area](/img/af/b78eb3522160896d77d9e82f7e7810.png)
[CTF attack and defense world] questions about backup in the web area

Cannot find a valid baseurl for repo: HDP-3.1-repo-1

集中式版本控制工具代码合并问题

IDEA导入外部项目时pom文件的依赖无效问题解决

Jenkins -- Basic -- 5.2 -- system configuration -- system configuration

李宏毅机器学习(2017版)_P13:深度学习

RS485 signal measurement
随机推荐
深度学习汇报(1)
李宏毅机器学习(2021版)_P5-6:小梯度处理
Longest common substring
SQL learning (3) -- complex query and function operation of tables
Jenkins--基础--5.1--系统配置--插件管理
4. European Champions League
Jenkins--基础--5.3--系统配置--全局安全配置
Verilog的基本语法
05 - attack and defense of phishing websites
Play guest cloud with zerotier nanny level teaching to ensure learning waste
李宏毅机器学习(2017版)_P14:反向传播
More than live streaming: what other eye-catching functions does Tencent cloud live mlvb plug-in have besides streaming / streaming
数据库期中(一)
复杂度OJ题
RS485信号的测量
Small programs related to a large number of digital collections off the shelves of wechat: is NFT products the future or a trap?
Android -- Data Persistence Technology (III) database storage
集中式版本控制工具代码合并问题
堆排序相关知识总结
Li Hongyi machine learning (2021 Edition)_ P7-9: training skills