Esempio n. 1
0
//		public void CancelMess()
//		{
//			Agent agent = (Agent)rvoAgent;
//			AIPath myAi = GetComponent<AIPath> ();
//			if (myAi.isSingleSearch) {
//				List<Agent> neighours = agent.neighbours;
//				myAi.CancelCurrentPath ();
//
//			}
//		}
        public void FindNeighour()
        {
            Agent  agent = (Agent)rvoAgent;
            AIPath myAi  = GetComponent <AIPath> ();

            if (myAi.TargetReached)
            {
                return;
            }

            List <Agent> neighours = agent.neighbours;

            if (myAi.isSingleSearch)
            {
                for (int i = 0; i < neighours.Count; i++)
                {
                    if (neighours == null || neighours[i] == null || neighours[i].parent == null)
                    {
                        continue;
                    }
                    if (i >= neighours.Count || i < 0)
                    {
                        continue;
                    }
                    AIPath neighourAi = neighours[i].parent.GetComponent <AIPath>();
                    if (myAi.CheckInLine(myAi.lastTargetPos, neighourAi.GetFeetPosition()))
                    {
                        float ABDist = (myAi.lastTargetPos - myAi.GetFeetPosition()).magnitude;
                        if (ABDist < neighbourDist * 2)
                        {
                            myAi.OnTargetReached();
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < neighours.Count; i++)
                {
                    if (neighours == null || neighours[i] == null || neighours[i].parent == null)
                    {
                        continue;
                    }
                    if (i >= neighours.Count || i < 0)
                    {
                        continue;
                    }
                    AIPath neighourAi = neighours[i].parent.GetComponent <AIPath>();
                    if (neighourAi != null && neighourAi.TargetReached)
                    {
                        //myAi.OnTargetReached();
                        if (myAi.CheckInLine(myAi.GetFeetPosition(), neighourAi.GetFeetPosition()))
                        {
                            if (myAi.lastTargetPos != Vector3.zero)
                            {
                                Vector3 dir = myAi.lastTargetPos - myAi.GetFeetPosition();

                                Vector3 up = Vector3.Cross(dir, Vector3.right);
                                if (lastMoveTime + 0.1 > Time.realtimeSinceStartup)
                                {
                                    rotateposi  *= -1;
                                    lastMoveTime = Time.realtimeSinceStartup;
                                }
                                dir = Quaternion.AngleAxis(rotateposi * 90, up) * dir * (maxSpeed);
                                //myAi.endReachedDistance = 3.0f;

                                Move(dir);
                            }
                        }

                        break;
                    }
                }
            }
        }