目录

isGrounded   在上次移动期间 CharacterController 是否接触地面?


isGrounded   在上次移动期间 CharacterController 是否接触地面?

测试:

俩方块 player 和 land

player上挂  CharacterController

land

脚本挂在player上

用  CharacterController.Move 方法才能触发落地

public class test1010 : MonoBehaviour
{
    CharacterController controller;
 
    Vector3 velocity = default(Vector3); //初始化
    void Start()
    {
        controller = this.GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {

        float dt = Time.deltaTime;  //帧时间
        velocity += new Vector3(0, -10, 0);
        controller.Move(velocity * dt);
       //this.transform.position = velocity;  // 不打印
        if (controller.isGrounded)
        {
            print("true");
        }

    }
}

更多推荐