抓住物体时角色无法控制地移动

时间:2019-06-12 13:52:06

标签: c# unity3d collision-detection

我的游戏确实发生了一些奇怪的事情。当角色抓住一个对象时,他开始不受控制地移动,并且输入被反转。例如,如果我按下使角色向右移动的按钮,则他向左移动,反之亦然。我不知道这是怎么回事。该对象具有一个盒子碰撞器。玩家有一个与他连接的球体碰撞器。

此对象越大,角色移动得越快。我真的不知道我使用此代码来选择对象。

private void OnTriggerStay(Collider other)
{
    if (other.tag == "PlayerCollider")
    {
        Player.PodeLargar = false;
    }

    if (Input.GetButtonDown("Jump") && other.tag == "PlayerCollider" && !Player.Segurando && !ItemEmCima)
    {
        StartCoroutine(PegarItem());
    }

    if (Input.GetButtonDown("Jump") && other.tag == "PlayerCollider" && Player.Segurando && !ItemEmCima)
    {
        StartCoroutine(Player.PosicionarItem(this.transform));
        ItemEmCima = true;
    }

    if (Input.GetButtonDown("Jump") && other.tag == "PlayerCollider" && Player.Segurando && !ItemEmCima /*|| other.gameObject.tag != "Espaço1.1" || other.gameObject.tag != "Incisivo"*/)
    {
        Player.PodeLargar = false;
    }

    if (Input.GetButtonDown("Jump") && other.tag == "PlayerCollider" && !Player.Segurando && ItemEmCima)
    {
        EmCima = this.transform.GetChild(1).gameObject;
        LugarErrado = false;
        StartCoroutine(PegarDaBancada(EmCima));
    }
}

private void OnTriggerExit(Collider other)
{
    if (other.tag == "PlayerCollider")
    {
        Player.PodeLargar = true;
    }
}

//----Coroutines---------------------------------------------------------
IEnumerator PegarItem()
{
    //Instantiate(DenteRespectivo, ColliderTrans.position, ColliderTrans.rotation, ColliderTrans.transform);
    yield return new WaitForSeconds(0.1f);
    Player.Segurando = true;
}

IEnumerator PegarDaBancada(GameObject Objeto)
{
    Objeto.transform.parent = ColliderTrans.transform;
    Objeto.transform.position = ColliderTrans.position;
    Objeto.transform.rotation = ColliderTrans.rotation;

    yield return new WaitForSeconds(0.1f);
    Player.Segurando = true;
    ItemEmCima = false;
}

0 个答案:

没有答案