Пример #1
0
    //提前判断走完后各个方向是否会造成碰撞,沿不会碰撞的方向走
    public void SetPosWithJudgeCollide(Vector3 newPos)
    {
        Vector3 oldPos    = objectbase.realLocalPos;
        Vector3 tempPos   = oldPos;
        Vector3 targetPos = oldPos;

        //因为只要有一维不层叠就不会碰撞,就可以走过去

        tempPos.x = newPos.x;
        objectbase.realLocalPos = tempPos;
        if (!ColliderManager.IsInCollision(objectbase))
        {
            targetPos.x = newPos.x;
        }

        tempPos.x = oldPos.x;
        tempPos.y = newPos.y;
        objectbase.realLocalPos = tempPos;
        if (!ColliderManager.IsInCollision(objectbase))
        {
            targetPos.y = newPos.y;
        }

        tempPos.y = oldPos.y;
        tempPos.z = newPos.z;
        objectbase.realLocalPos = tempPos;
        if (!ColliderManager.IsInCollision(objectbase))
        {
            targetPos.z = newPos.z;
        }

        objectbase.realLocalPos = targetPos;
    }