Ejemplo n.º 1
0
        private RVOObject[] FindAIEntity(Vector3 center, float maxdis, GameObject pg)
        {
            Collider[]       tCollider      = Physics.OverlapSphere(center, maxdis);
            List <RVOObject> tListRVOObject = new List <RVOObject> ();

            for (int i = 0; i < tCollider.Length; i++)
            {
                float dis1 = Vector3.Distance(pg.transform.position, tCollider[i].gameObject.transform.position);
                //	Debug.Log (pg.transform.position.ToString());
                if (tCollider [i].tag == AITag && dis1 > 1.0f)
                {
                    bool isFind = false;
                    for (int j = 0; j < this.mWorld.mEntityCount; j++)
                    {
                        if (isFind)
                        {
                            break;
                        }
                        BaseAIComponent bAI = mWorld.mUEntity [j].GetComponent <BaseAIComponent> ();
                        if (bAI != null)
                        {
                            float dis = Vector3.Distance(bAI.mAIRT.transform.position, tCollider[i].gameObject.transform.position);
                            if (dis < 0.5f)
                            {
                                //Debug.Log (dis1+"  "+dis);
                                RVOObject tRVOObject = new RVOObject();
                                tRVOObject.mpos      = bAI.mAIRT.transform.position;
                                tRVOObject.mvelocity = mWorld.mUEntity [j].GetComponent <AIMove> ().mDirection *mWorld.mUEntity [j].GetComponent <AIMove> ().mVelocity;
                                tListRVOObject.Add(tRVOObject);
                                isFind = true;
                            }
                        }
                        else
                        {
                            AIMove aim = mWorld.mUEntity [j].GetComponent <AIMove> ();
                            if (aim != null)
                            {
                                GameObject g   = ((SimpleAI)(mWorld.mUEntity [j])).mAIRT;
                                float      dis = Vector3.Distance(g.transform.position, tCollider[i].gameObject.transform.position);
                                if (dis < 0.5f)
                                {
                                    RVOObject tRVOObject = new RVOObject();
                                    tRVOObject.mpos      = g.transform.position;
                                    tRVOObject.mvelocity = aim.mDirection * aim.mVelocity;
                                    tListRVOObject.Add(tRVOObject);
                                    isFind = true;
                                }
                            }
                        }
                    }
                }
            }
            return(tListRVOObject.ToArray());
        }
Ejemplo n.º 2
0
        private RVOObject[] FindObestacle(Vector3 center, float maxdis)
        {
            Collider[] tCollider = Physics.OverlapSphere(center, maxdis);
            //Debug.Log (tCollider.Length);
            List <RVOObject> tListRVOObject = new List <RVOObject> ();

            for (int i = 0; i < tCollider.Length; i++)
            {
                if (tCollider [i].tag == collisionTag)
                {
                    RVOObject tRVOObject = new RVOObject();
                    tRVOObject.mpos      = tCollider [i].transform.position;
                    tRVOObject.mvelocity = Vector3.zero;
                    tListRVOObject.Add(tRVOObject);
                }
            }
            return(tListRVOObject.ToArray());
        }