Пример #1
0
    Vector3 getNextMove()
    {
        Vector3 coords      = Vector3.zero;
        Vector3 norm        = Vector3.zero;
        bool    notgrounded = false;

        Vector3 targetPosition = camera.transform.position;

        ai_target = AI_TARGET.PLAYER;

        /*
         * if (tag == "Pet") {
         *      for (int i=0; i<itemspawn.items.Length; i++) {
         *              if (itemspawn.spawneditems [i] == null || itemspawn.spawneditems [i].GetComponent<TriggerScript> ().triggered)
         *                      continue;
         *
         *              float groundLength = (itemspawn.spawneditems [i].transform.position - transform.position).magnitude;
         *              if (groundLength < vxe.voxel_size * 20) {
         *                      targetPosition = itemspawn.spawneditems [i].transform.position;
         *                      ai_target = AI_TARGET.SHEEP;
         *                      break;
         *              }
         *      }
         * }
         */
        Vector3 rawdir = Vector3.ProjectOnPlane((targetPosition - transform.position), Vector3.up);
        Vector3 dir    = rawdir.normalized;

        //Debug.Log ( "dist: " + rawdir.magnitude + " " + playerFaceThreshold);

        if (ai_target == AI_TARGET.PLAYER && rawdir.magnitude < playerFaceThreshold)
        {
            ai_state = AI_STATE.STOPPED;
            return(dir);
        }

        bool hit = vxe.GroundedRayCast(transform.position, dir, STEP, ref coords, ref norm, ref notgrounded, 0.5f);

        if (!hit)
        {
            if (notgrounded)
            {
                bool isThereGround = vxe.RayCast(coords, Vector3.down, BIG_STEP, ref fallPosition, ref norm, 0.5f);
                if (isThereGround)
                {
                    fallPosition += Vector3.up * vxe.voxel_size * 0.5f;
                    ai_state      = AI_STATE.FALLING;
                    return(dir);
                }
            }
            else
            {
                movePosition = coords;
                ai_state     = AI_STATE.MOVING;
                return(dir);
            }
        }
        else
        {
            bool isThereSurface = vxe.OccupiedRayCast(coords, Vector3.up, BIG_STEP, ref jumpPosition, ref norm);
            //bool ICannotJump = vxe.CheapRayCast(transform.position,Vector3.up, 5);
            if (isThereSurface)
            {
                jumpPosition -= Vector3.up * vxe.voxel_size * 0.5f;
                ai_state      = AI_STATE.JUMPING;
                return(dir);
            }
        }

        ai_state = AI_STATE.STOPPED;
        return(Vector3.zero);
    }
Пример #2
0
    Vector3 getNextMoveLimited()
    {
        Vector3 targetPosition = camera.transform.position;

        ai_target = AI_TARGET.PLAYER;

        /*
         * if (tag == "Pet") {
         *      for (int i=0; i<itemspawn.items.Length; i++) {
         *              if (itemspawn.spawneditems [i] == null || itemspawn.spawneditems [i].GetComponent<TriggerScript> ().triggered)
         *                      continue;
         *
         *              float groundLength = (itemspawn.spawneditems [i].transform.position - transform.position).magnitude;
         *              if (groundLength < vxe.voxel_size * 20) {
         *                      targetPosition = itemspawn.spawneditems [i].transform.position;
         *                      ai_target = AI_TARGET.SHEEP;
         *                      break;
         *              }
         *      }
         * }
         */
        Vector3 camtome = (targetPosition - transform.position);
        Vector3 rawdir  = Vector3.ProjectOnPlane(camtome, Vector3.up);
        Vector3 dir     = rawdir.normalized;

        if (ai_target == AI_TARGET.PLAYER && rawdir.magnitude < playerFaceThreshold)
        {
            ai_state = AI_STATE.STOPPED;
            return(dir);
        }

        Vector3 coords      = Vector3.zero;
        Vector3 norm        = Vector3.zero;
        bool    notgrounded = false;

        bool hit = vxe.GroundedRayCast(transform.position, dir, STEP, ref coords, ref norm, ref notgrounded, 0.5f);


        Vector3 jumpDir = Vector3.zero;
        bool    canJump = checkForJumpPositions(dir, out jumpDir);
        float   jumpPositionToTarget = (jumpPosition - targetPosition).sqrMagnitude;
        float   movePositionToTarget = (coords - targetPosition).sqrMagnitude;



        if (!hit)
        {
            if (canJump && jumpPositionToTarget < movePositionToTarget)
            {
                ai_state = AI_STATE.JUMPING;
                return(jumpDir);
            }

            if (notgrounded)
            {
                bool isThereGround = vxe.RayCast(coords, Vector3.down, BIG_STEP, ref fallPosition, ref norm, 0.5f);
                if (isThereGround)
                {
                    fallPosition += Vector3.up * vxe.voxel_size * 0.5f;
                    ai_state      = AI_STATE.FALLING;
                    return(dir);
                }
            }
            else
            {
                movePosition = coords;
                ai_state     = AI_STATE.MOVING;
                return(dir);
            }
        }
        else
        {
            bool isThereSurface = vxe.OccupiedRayCast(coords, Vector3.up, BIG_STEP, ref jumpPosition, ref norm);
            if (isThereSurface)
            {
                jumpPosition -= Vector3.up * vxe.voxel_size * 0.5f;
                ai_state      = AI_STATE.JUMPING;
                return(dir);
            }
        }

        ai_state = AI_STATE.STOPPED;
        return(dir);
    }
Пример #3
0
    Vector3 getNextMoveLimited()
    {
        Vector3 targetPosition = camera.transform.position;
        ai_target = AI_TARGET.PLAYER;

        if (tag == "Pet")
        {
            for (int i=0; i<itemspawn.items.Length; i++)
            {
                if (itemspawn.spawneditems [i] == null || itemspawn.spawneditems [i].GetComponent<TriggerScript> ().triggered)
                    continue;

                float groundLength = (itemspawn.spawneditems [i].transform.position - transform.position).magnitude;
                if (groundLength < vxe.voxel_size * 15)
                {
                    targetPosition = itemspawn.spawneditems [i].transform.position;
                    ai_target = AI_TARGET.SHEEP;
                    break;
                }
            }
        }

        Vector3 rawdir = Vector3.ProjectOnPlane ((targetPosition - transform.position), Vector3.up);
        Vector3 dir = rawdir.normalized;

        //Debug.Log ( "dist: " + rawdir.magnitude + " " + playerFaceThreshold);

        if(ai_target == AI_TARGET.PLAYER && rawdir.magnitude < playerFaceThreshold)
        {
            ai_state = AI_STATE.STOPPED;
            return dir;
        }

        Vector3 coords = Vector3.zero;
        Vector3 norm = Vector3.zero;
        bool notgrounded = false;

        bool hit = vxe.GroundedRayCast (transform.position, dir, STEP, ref coords, ref norm, ref notgrounded, 0.5f);

        Vector3 jumpDir = Vector3.zero;
        bool canJump = checkForJumpPositions (dir, out jumpDir);
        float jumpPositionToTarget = (jumpPosition - targetPosition).sqrMagnitude;
        float movePositionToTarget = (coords - targetPosition).sqrMagnitude;

        if(canJump && jumpPositionToTarget < movePositionToTarget)
        {
            ai_state = AI_STATE.JUMPING;
            return jumpDir;
        }

        if(!hit)
        {
            if(notgrounded)
            {
                bool isThereGround = vxe.RayCast (coords, Vector3.down, BIG_STEP, ref fallPosition, ref norm, 0.5f);
                if(isThereGround)
                {
                    fallPosition += Vector3.up * vxe.voxel_size * 0.5f;
                    ai_state = AI_STATE.FALLING;
                    return dir;
                }
            }
            else
            {
                movePosition = coords;
                ai_state = AI_STATE.MOVING;
                return dir;
            }
        }
        else
        {
            bool isThereSurface = vxe.OccupiedRayCast (coords, Vector3.up, JUMP_RANGE, ref jumpPosition, ref norm);
            if(isThereSurface)
            {
                jumpPosition -= Vector3.up * vxe.voxel_size * 0.5f;
                ai_state = AI_STATE.JUMPING;
                return dir;
            }
        }

        ai_state = AI_STATE.STOPPED;
        return dir;
    }