Exemplo n.º 1
0
    /*
     * void OnMouseDrag() {
     *
     *      Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
     *
     *      Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
     *      transform.position = curPosition;
     * }
     */

    void Move()
    {
        Vector3 prevPos = pos;
        Vector3 newPos  = transform.position;

        /* DEBUG */
        //uint one = steeringManager.ReturnOne();
        //Debug.Log("At time " + Time.time + " print one: " + one);
        /* END_DEBUG */

        uint newPol = steeringManager.GetClosestPolygon(newPos);

        if (newPol != polyRef)
        {
            steeringManager.DecrNumObjectsInPolygon(polyRef);
            steeringManager.IncrNumObjectsInPolygon(newPol);

            uint prevNum = steeringManager.GetNumOjbectsInPolygon(polyRef);
            uint newNum  = steeringManager.GetNumOjbectsInPolygon(newPol);

            Debug.Log("At time " + Time.deltaTime + ", PrevPol = " + polyRef + " has " + prevNum + " objects, and NewPol = " + newPol + " has " + newNum + " objects");

            polyRef = newPol;
        }
    }
Exemplo n.º 2
0
    public void MoveAlongAnimationCurves(float time)
    {
        if (I_AM_ALEJANDRO)
        {
            if (curves == null)
            {
                return;
            }
        }
        else
        {
            curves = agent_.GetPlanAnimationCurve();
        }

        float x = curves[0].Evaluate(time);
        float y = curves[1].Evaluate(time);
        float z = curves[2].Evaluate(time);

        agentSpeed = curves[3].Evaluate(time);

        Vector3 newPos = new Vector3(x, y, z);

        //Debug.Log("At time " + time + " pos = " + newPos);

        prevPos = transform.position;

        transform.position = newPos;

        Vector3 mov = newPos - prevPos;

        if (mov.magnitude > 0.0001f)
        {
            Vector2 movPlane     = new Vector2(mov.x, mov.z);
            Vector2 forwardPlane = new Vector2(transform.forward.x, transform.forward.z);
            float   angle        = Vector2.Angle(movPlane, forwardPlane);
            if (agentSpeed >= 1.75f && Mathf.Abs(angle) <= 100 && locoState_ != "Locomotion_LadderAnimation")
            {
                transform.forward = mov;
            }
            else
            {
                transform.forward = Vector3.Slerp(transform.forward, mov, Time.deltaTime);
            }

            agent_.SetCurrentSpeed(agentSpeed);

            if (steeringManager != null)
            {
                uint newPol = steeringManager.GetClosestPolygon(newPos);

                if (newPol != polyRef)
                {
                    steeringManager.DecrNumObjectsInPolygon(polyRef);
                    steeringManager.IncrNumObjectsInPolygon(newPol);

                    uint prevNum = steeringManager.GetNumOjbectsInPolygon(polyRef);
                    uint newNum  = steeringManager.GetNumOjbectsInPolygon(newPol);

                    //Debug.Log("At time " + Time.deltaTime + ", PrevPol = " + polyRef + " has " + prevNum + " objects, and NewPol = " + newPol + " has " + newNum + " objects");

                    polyRef = newPol;
                }
            }
        }
        else
        {
            agentSpeed = 0;
        }
    }