当前位置:网站首页>Unity CharacterController
Unity CharacterController
2022-07-27 01:24:00 【Calm nine】
Unity CharacterController Use
introduction
CharacterController yes Unity Built in components , It is often used in third person or first person role control , It can be simply regarded as a capsule collision body that can specify the moving direction , The character controller allows you to move easily under collision constraints , Without dealing with rigid bodies .
Components

| attribute | Introduce |
|---|---|
| Slope Limit | The maximum angle that a character can climb |
| Step Offset | The maximum height that a character can climb a step |
| Skin Width | Two characterController The maximum depth that can penetrate each other's skin , High values reduce jitter , A low value can easily cause the character to get stuck , A good value is Radius Of 10%. If your character gets stuck all the time , It is possible that this value is too small . |
| Min Move Distance | Minimum moving distance , If the moving distance is lower than this value , It doesn't move . It can reduce the jitter of characters . |
| Center | The center point of the capsule collider |
| Radius | The radius of the capsule impactor ( Fat and thin ) |
| Height | The height of the capsule impactor |
SimpleMove and Move
difference
Move SimpleMove The official introduction Supplies the movement of a GameObject with an attached CharacterController component. Moves the character with speed. Parameters Along the y The speed of the shaft is ignored . Speed in meters / Seconds per unit . Gravity is applied automatically . When moving, you need to multiply it by time gravity Gravity is applied automatically There's no gravity , You have to add it yourself Return value bool, Whether it is attached to the ground CollisionFlags, Collision information void Update() { controller.SimpleMove(forward * speed); controller.Move(forward * speed * Time.deltaTime); }It is recommended to call only once per frame Move perhaps SimpleMove
Physical effects
CharacterController Will not be affected by any force , It will not exert any force on any object .
If you want to achieve physical effects , You can add the effect you want to achieve in the following events
| event | describe |
|---|---|
| OnCollisionEnter | collider Get into controller Trigger when |
| OnCollisionExit | collider from controller Triggered when leaving inside |
| OnCollisionStay | Yes Collider Stay at controller Internal time trigger |
| OnTriggerEnter | trigger Get into controller Trigger when |
| OnTriggerExit | trigger from controller Triggered when leaving inside |
| OnTriggerStay | Yes trigger Stay at controller Internal time trigger |
| OnControllerColliderHit | And others controller Trigger on collision |
private void OnControllerColliderHit(ControllerColliderHit hit)
{
float power = 2.0F;
Rigidbody hitRigidBody = hit.collider.attachedRigidbody;
if (hitRigidBody == null || hitRigidBody.isKinematic)
{
return;
}
// Attach the force corresponding to the current speed to the collision object
hitRigidBody.AddForce(_Controller.velocity * power);
}
Reference material
【Unity Learning notes 】CharacterController Components _ A blog of Bai Mengren -CSDN Blog _charactercontroller Components 
边栏推荐
- Li Hongyi machine learning (2017 Edition)_ P6-8: gradient descent
- Jenkins -- Basic -- 5.2 -- system configuration -- system configuration
- Pytorch tensor data basic operation
- Spark accumulator
- markdown
- Li Hongyi machine learning (2021 Edition)_ P5-6: small gradient processing
- 集中式版本控制工具代码合并问题
- FaceNet
- The basic concept of how Tencent cloud mlvb technology can highlight the siege in mobile live broadcasting services
- Unity[1] 学习目录
猜你喜欢
随机推荐
RS485 signal measurement
【unity】Unity界面scene视图[1]
创建MDK工程
Li Hongyi machine learning (2021 Edition)_ P5-6: small gradient processing
#高级语言 各种开发软件介绍
FaceNet
Naive Bayes Multiclass训练模型
MySQL关闭连接事务自动提交的问题
Jenkins--基础--02--安装
Li Kou brushes 300 record posts
做题笔记1
Warning: IPv4 forwarding is disabled Networking will not work.
SQL learning (3) -- complex query and function operation of tables
Deep understanding of pod objects: basic management
SQL学习(1)——表相关操作
Next generation Internet: Video Networking
Cannot find a valid baseurl for repo: HDP-3.1-repo-1
吴恩达深度学习系列教学视频学习笔记(一)——用于二分类的logistic回归函数
The MySQL character set is set to UTF-8, but the console still has the problem of Chinese garbled code
How to open ads for profit after uni app develops apps and plug-ins: uni ad

![数学建模简介-从现实对象到数学建模[2]](/img/b5/595a4e9a9a59ab57f541d3e21fba49.jpg)






