示例#1
0
    void Update()
    {
        // _isGrounded = Physics.CheckSphere(_groundChecker.position, GroundDistance, Ground, QueryTriggerInteraction.Ignore);

        maxIM = iMap.FindMaxPoint();
        if (maxIM[0] > 1.0f)
        {
            pathScript.target = new Vector3(maxIM[1], 0.5f, maxIM[2]);
            //  print("X: " + maxIM[1] + "Y: " + maxIM[2]);

            if (Vector3.Distance(transform.position, pathScript.target) < 1.1f)
            {
                //iMap.SetPointOne(pathScript.target);
                print(gameObject.name + ": FIIIIND IIIT!!");
            }
        }
        else if (targetIM.GetIMvalue(transform.position) > 0)
        {
            float[] ret = targetIM.GetHighestSmell(transform.position, GridScript);
            pathScript.target = new Vector3(ret[1], 0.5f, ret[2]);
            Node n = GridScript.GetNodeFromWorldPos(new Vector3(ret[1], 0.5f, ret[2]));
            print(gameObject.name + ": Following smell" + ret[0] + "PosSmell: " + targetIM.GetIMvalue(transform.position) + " walkable: " + n.walkable);
            print(gameObject.name + ": target poing: " + new Vector3(ret[1], 0.5f, ret[2]) + " stand point: " + transform.position);
        }
        else if (enemyIM.GetIMvalue(transform.position) > 0.1)
        {
            float[] returLow = enemyIM.GetLowestSmell(transform.position, GridScript);


            pathScript.target = new Vector3(returLow[1], 0.5f, returLow[2]);
            Node nA = GridScript.GetNodeFromWorldPos(new Vector3(returLow[1], 0.5f, returLow[2]));

            print(gameObject.name + ":Springer från lukt" + returLow[0] + " PosSmell: " + enemyIM.GetIMvalue(transform.position) + " walkable: " + nA.walkable);
        }
        else
        {
            if (state == 1)   //move around
            {
                //print(Vector3.Distance(transform.position, pathScript.target));
                seekNode = GridScript.GetNodeFromWorldPos(pathScript.target);

                if ((Vector3.Distance(transform.position, pathScript.target) < 1.1f) || !seekNode.walkable)
                {
                    minIM = iMap.FindMinPoint();
                }

                pathScript.target    = new Vector3(minIM[0], 0.5f, minIM[1]);
                pathScript.AllowMove = true;
            }
            else if (state == 0) //state 0, stay
            {
                pathScript.AllowMove = false;
                transform.RotateAround(transform.position, Vector3.up, rot * turnspeed * Time.deltaTime);
            }
        }
    }