【问题标题】:ThirdPersonController moving stuttering when the character collider colliding with a cube collider?当角色碰撞器与立方体碰撞器碰撞时,ThirdPersonController 移动口吃?
【发布时间】:2017-12-05 09:28:44
【问题描述】:

我正在尝试将玩家移动到他所面对的玩家方向 1.5 距离。 立方体比例是 1,1,1,所以我猜在逻辑上玩家应该落在立方体之间,这是另一个要解决的问题,我可以使立方体在 Y 上的比例为 0.1。

但现在的问题是玩家开始向前移动,但随后他卡在空中结结巴巴。

private void MovePlayer(float speed)
    {
        player.position += player.forward * Time.deltaTime * speed;
    }

    private void Update()
    {
        Vector3 newPos = new Vector3(player.position.x + 1.5f, player.position.y, player.position.z);
        MovePlayer(1f);
    }

当游戏运行时,玩家一直口吃,因为他试图继续移动但被碰撞器卡住了。

另一个相关的问题是在许多情况下玩家在空中,看起来像是坐在而不是站在立方体上。只有当我用他站立的键移动玩家一点时。

【问题讨论】:

    标签: c# unity3d unity5


    【解决方案1】:

    有两个可能的问题。

    1。您没有禁用ThirdPersonUserControl 脚本。请注意,ThirdPersonUserControl 脚本附加到 ThirdPersonController 游戏对象。您必须禁用它,否则您将同时从两个脚本中移动播放器。

    2.ThirdPersonController 使用Rigidbody。不要使用变换 (player.position) 移动 Rigidbody 对象。您必须使用刚体的功能之一,例如 MovePositionAddForcethis 帖子中描述的速度。

    由于这是ThirdPersonController,因此您不应直接修改Rigidbody。使用那里声明的Move 函数来移动它。您可以将新位置传递给第一个参数,然后分别将粉碎和跳转值传递给第二个和第三个参数。这必须在 FixedUpdate 更新中完成。

    正确移动ThirdPersonCharacter对象的示例:

    ThirdPersonCharacter tpsScript;
    
    void Start()
    {
        GameObject tpsObj = GameObject.Find("ThirdPersonController");
        tpsScript = tpsObj.GetComponent<ThirdPersonCharacter>();
    }
    
    void FixedUpdate()
    {
    
        float h = CrossPlatformInputManager.GetAxis("Horizontal");
        float v = CrossPlatformInputManager.GetAxis("Vertical");
    
        Transform m_Cam = Camera.main.transform;
        Vector3 m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
        Vector3 m_Move = v * m_CamForward + h * m_Cam.right;
    
        tpsScript.Move(m_Move, false, false);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      相关资源
      最近更新 更多