Ejemplo n.º 1
0
    Vector3 generateTarget()
    {
        // generate according to the robot's position
        //Vector3 robotDis = rbtObj.transform.position - _table.transform.position;
        Vector3 mir       = 2 * _table.transform.position - rbtObj.transform.position;
        float   tableSize = 1f;
        // generate two points for bezier generation and
        // algorithms3
        float deltax = Random.Range(Mathf.Max(-20f + _table.transform.position.x * 100f, -15 + mir.x * 100f),
                                    Mathf.Min(20f + _table.transform.position.x * 100f, 15 + mir.x * 100f)) / 100.0f;
        float deltaz = Random.Range(Mathf.Max(-20f + _table.transform.position.z * 100f, -15 + mir.z * 100f),
                                    Mathf.Min(20f + _table.transform.position.z * 100f, 15 + mir.z * 100f)) / 100.0f;

        print("dx:\t" + deltax + "\tdy:\t" + deltaz + "\trbt:\t" + rbtObj.transform.position + "\ttbl:\t" + _table.transform.position);

        while (Vector3.Distance(rbtObj.transform.position, new Vector3(deltax, rbtObj.transform.position.y, deltaz)) < 0.2f)
        {
            print("redo");
            deltax = Random.Range(-20, 20) / 100.0f + _table.transform.position.x;
            deltaz = Random.Range(-20, 20) / 100.0f + _table.transform.position.z;
        }
        deltax = Mathf.Min(_table.transform.position.x + 0.2f, deltax);
        deltax = Mathf.Max(_table.transform.position.x - 0.2f, deltax);
        deltaz = Mathf.Min(_table.transform.position.z + 0.2f, deltaz);
        deltaz = Mathf.Max(_table.transform.position.z - 0.2f, deltaz);

        Vector3 des = new Vector3(deltax * tableSize, _table.transform.position.y, deltaz * tableSize);         // + _table.transform.position;

        print("des:\t" + des.ToString("F3"));

        //ONLY FOR TEST
        if (_DEBUG)
        {
            des = _table.transform.position;
        }

        // try two way animation that it goes to some floating place first and then get on the table
        Vector3 desForRbt = des;

        des.y += (transform.position.y - _table.transform.position.y) / 3f;

        // another two points
        float   disx = Random.Range(1, 3) * (Random.Range(0, 1) * 2 - 1);
        float   disy = Random.Range(1, 3) * (Random.Range(0, 1) * 2 - 1);
        Vector3 p2   = (transform.position + des) / 2 + new Vector3(disx, disy, 0);
        Vector3 p3   = (transform.position + des) / 2 - new Vector3(disx, disy, 0);

        // generate bezier path
        _path = new bezier(transform.position, p2, p3, des);

        // generate the first destination
        moveDestination = _path.getPoint(0.0f);

        // reset the speed
        speed = 0.05f;

        return(desForRbt);
    }
Ejemplo n.º 2
0
    void moving()
    {
        if (_isMoving)
        {
            //print ("moving");
            showWings();
            //print ("moving:\t" + t);
            float curDis = Vector3.Distance(transform.position, moveDestination);
            print("cur dis:\t" + curDis);

            if (_hasRbtArrived)
            {
                if (curDis < 0.08f)
                {
                    _isMoving = false;
                    hideWings();
                    _isLinkRbt = true;
                    print("arrived");
                }
            }
            else if (curDis < 0.08f)
            {
                t = Mathf.Min(t + 0.01f, 1.0f);

                moveRotation    = transform.rotation * Quaternion.Euler(new Vector3(Random.Range(0, 20), Random.Range(-0, 35), Random.Range(-0, 30)));
                moveDestination = _path.getPoint(t);
                if (t > 0.999f)
                {
                    moveRotation = Quaternion.identity;
                    //print ("moving rot:\t" + moveRotation);
                }
                startPos = transform.position;
                startRot = transform.rotation;
            }
            movingTo();
        }
    }