首页 > 解决方案 > 为什么我在 Unity 中的 Player 在我启动 PlayMode 时会摔倒?

问题描述

视频讲解

我在 Unity 中的立方体随机掉落。它位于一个名为“Ground”的立方体上,下面附有一个移动脚本。上面是显示发生了什么的视频,我也会附上一张图片。图片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ThirdPersonMovement : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 6f;


    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

        if (direction.magnitude >= 0.1f)
        {
            controller.Move(direction * speed * Time.deltaTime);

        }
    }
}

标签: c#unity3d

解决方案


确保 colider 覆盖整个立方体,因为现在它在所有轴上的大小仅为 1。在此处输入图像描述


推荐阅读