CharacterController官方注释

Unity的CharacterController组件提供了一种简单的方式来进行受碰撞约束的移动,无需处理刚体和碰撞体。它有两种移动方法:SimpleMove()适用于地面移动,自动应用重力,Y轴速度受限;Move()则更复杂,不受重力影响,可滑动并检测碰撞,适用于实现跳跃等行为。CollisionFlags属性用于描述碰撞情况,OnControllerColliderHit方法在发生碰撞时触发,可用于推动碰撞物体。

Character Controller API

官方注释:

A CharacterController allows you to easily do movement constrained by collisions without having to deal with a rigidbody.

也就是说,角色控制器自带的移动函数包含了碰撞体,不用再让我们自己设置刚体和碰撞体了.

这个组件有两个移动函数可以使用.

SimpleMove()

Moves the character with speed.
Velocity along the y-axis is ignored. Speed is in meters/s. Gravity is automatically applied. Returns if the character is grounded. It is recommended that you make only one call to Move or SimpleMove per frame.

最重要的一点就是,这个函数的Y轴速度是被限制了的.这个方法自带Gravity即重力属性,需要接地,所以物体不能腾空运动.这个方法接收一个速度向量.

下面是官方示例:

  using UnityEngine;
  using System.Collections;

 [RequireComponent(typeof(CharacterController))]
 public class ExampleClass : MonoBehaviour {
 public float speed = 3.0F;
 public float rotateSpeed = 3.0F;
 void Update() {
    CharacterController controller = GetComponent<CharacterController>();
    transform.Rotate(0, Input.GetAxis("Ho
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卿屿­­­­­­­-轻尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值