Beispiel #1
0
    void GetEscapePath(Path p)
    {
        if (p.error)
        {
            Debug.Log("Aw Crap!!! The Path Failed! This Means That The Pathfinder Deserves A Beatdown!!!!!!!!!!!");
            return;
        }
        FleePath fPath = p as FleePath;


        List <GraphNode> nodeList      = fPath.path;
        List <Vector3>   pointList     = PathUtilities.GetPointsOnNodes(nodeList, 25, 10);
        Vector3          farthestPoint = target.transform.position;

        for (int i = 0; i < pointList.Count; i++)
        {
            if (Vector3.Distance(pointList[i], target.transform.position) > Vector3.Distance(farthestPoint, target.transform.position))
            {
                farthestPoint = pointList[i];
            }
        }



        Debug.DrawLine(this.transform.position, farthestPoint);

        ai.destination = farthestPoint;
    }
    /** Starts a path specified by PathTypesDemo.activeDemo */
    public void DemoPath()
    {
        Path p = null;

        if (activeDemo == 0)
        {
            p = ABPath.Construct(start.position, end.position, OnPathComplete);
        }
        else if (activeDemo == 1)
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == 2)
        {
            RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
            rp.spread        = spread;
            rp.aimStrength   = aimStrength;
            rp.aim           = end.position;
            rp.replaceChance = replaceChance;

            p = rp;
        }
        else if (activeDemo == 3)
        {
            FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength   = aimStrength;
            fp.replaceChance = replaceChance;
            fp.spread        = spread;

            p = fp;
        }
        else if (activeDemo == 4)
        {
            ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete);

            p = constPath;
        }
        else if (activeDemo == 5)
        {
            FloodPath fp = FloodPath.Construct(end.position, null);
            lastFlood = fp;
            p         = fp;
        }
        else if (activeDemo == 6 && lastFlood != null)
        {
            FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete);


            p = fp;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
Beispiel #3
0
        public void CalculatePath()
        {
            if (moveMode != MoveMode.follow && moveMode != MoveMode.followTo && moveMode != MoveMode.fleeContinuously)
            {
                path = null;
            }                          // do this to avoid instant finishing if the action had been called before and if the actor didn't move

            Vector3 targetPos;

            if (target.Value != null)
            {
                targetPos = target.Value.transform.position + targetPosition.Value;
            }
            else
            {
                targetPos = targetPosition.Value;
            }

            if (path != null && path.vectorPath.Count > 0 && (moveMode == MoveMode.follow || moveMode == MoveMode.followTo))
            {
                p = ABPath.Construct(nextPos, targetPos, OnPathComplete);
            }                                                                          // create path from next waypoint (to avoid jitter due to sudden direction change on path update) to closest/first node
            else if (moveMode != MoveMode.fleeContinuously && moveMode != MoveMode.flee && moveMode != MoveMode.randomPath)
            {
                p = ABPath.Construct(go.transform.position, targetPos, OnPathComplete);
            }                                                                                        // create path from current position to closest/first node

            else if (moveMode == MoveMode.fleeContinuously || moveMode == MoveMode.flee)
            {
                if (AstarPath.HasPro)
                {
                    p = FleePath.Construct(go.transform.position, targetPos, (int)(length.Value * 1000f), OnPathComplete);
                }                                                                                                                          // create path from current position to closest/first node
                else
                {
                    p = ABPath.Construct(go.transform.position, go.transform.position + (go.transform.position - targetPos).normalized * length.Value, OnPathComplete);
                }
            }
            else if (moveMode == MoveMode.randomPath)
            {
                if (AstarPath.HasPro)
                {
                    p = RandomPath.Construct(go.transform.position, (int)(length.Value * 1000f), OnPathComplete);
                }                    // create path from current position to closest/first node
                else                 // random direction! This is just a cheap immitation of the real randompath!
                {
                    p = ABPath.Construct(go.transform.position, go.transform.position + new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)).normalized *length.Value, OnPathComplete);
                }
            }

            AstarPath.StartPath(p);              //make the actual vector3 path which we'll use lateron.
            time = Time.time;
            return;
        }
Beispiel #4
0
        // Token: 0x060029EC RID: 10732 RVA: 0x001C21BC File Offset: 0x001C03BC
        private void DemoPath()
        {
            Path path = null;

            switch (this.activeDemo)
            {
            case PathTypesDemo.DemoMode.ABPath:
                path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete));
                break;

            case PathTypesDemo.DemoMode.MultiTargetPath:
                base.StartCoroutine(this.DemoMultiTargetPath());
                break;

            case PathTypesDemo.DemoMode.RandomPath:
            {
                RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
                randomPath.spread      = this.spread;
                randomPath.aimStrength = this.aimStrength;
                randomPath.aim         = this.end.position;
                path = randomPath;
                break;
            }

            case PathTypesDemo.DemoMode.FleePath:
            {
                FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
                fleePath.aimStrength = this.aimStrength;
                fleePath.spread      = this.spread;
                path = fleePath;
                break;
            }

            case PathTypesDemo.DemoMode.ConstantPath:
                base.StartCoroutine(this.DemoConstantPath());
                break;

            case PathTypesDemo.DemoMode.FloodPath:
                path = (this.lastFloodPath = FloodPath.Construct(this.end.position, null));
                break;

            case PathTypesDemo.DemoMode.FloodPathTracer:
                if (this.lastFloodPath != null)
                {
                    path = FloodPathTracer.Construct(this.end.position, this.lastFloodPath, new OnPathDelegate(this.OnPathComplete));
                }
                break;
            }
            if (path != null)
            {
                AstarPath.StartPath(path, false);
                this.lastPath = path;
            }
        }
Beispiel #5
0
        /// <summary>Starts a path specified by PathTypesDemo.activeDemo</summary>
        void DemoPath()
        {
            Path p = null;

            switch (activeDemo)
            {
            case DemoMode.ABPath:
                p = ABPath.Construct(start.position, end.position, OnPathComplete);
                break;

            case DemoMode.MultiTargetPath:
                StartCoroutine(DemoMultiTargetPath());
                break;

            case DemoMode.ConstantPath:
                StartCoroutine(DemoConstantPath());
                break;

            case DemoMode.RandomPath:
                RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
                rp.spread      = spread;
                rp.aimStrength = aimStrength;
                rp.aim         = end.position;

                p = rp;
                break;

            case DemoMode.FleePath:
                FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
                fp.aimStrength = aimStrength;
                fp.spread      = spread;

                p = fp;
                break;

            case DemoMode.FloodPath:
                p = lastFloodPath = FloodPath.Construct(end.position, null);
                break;

            case DemoMode.FloodPathTracer:
                if (lastFloodPath != null)
                {
                    FloodPathTracer fpt = FloodPathTracer.Construct(end.position, lastFloodPath, OnPathComplete);
                    p = fpt;
                }
                break;
            }

            if (p != null)
            {
                AstarPath.StartPath(p);
                lastPath = p;
            }
        }
    private void CalculateFleePath()
    {
        Player player = _entityManager.players[0];

        npc.StopFollowing();
        npc.aiPath.canSearch = false;

        FleePath fleePath = FleePath.Construct(npc.transform.position, player.transform.position, 1000 * 100);

        npc.aiPath.SetPath(fleePath);
        npc.aiPath.canMove = true;
        // npc.aiPath.maxSpeed = 3;
    }
Beispiel #7
0
    /** Starts a path specified by PathTypesDemo::activeDemo */
    public void DemoPath()
    {
        Path p = null;

        if (activeDemo == 0)
        {
            p = new Path(start.position, end.position, OnPathComplete);
        }
        else if (activeDemo == 1)
        {
            MultiTargetPath mp = new MultiTargetPath(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == 2)
        {
            RandomPath rp = new RandomPath(start.position, searchLength, OnPathComplete);
            rp.spread        = spread;
            rp.aimStrength   = aimStrength;
            rp.aim           = end.position;
            rp.replaceChance = replaceChance;

            p = rp;
        }
        else if (activeDemo == 3)
        {
            FleePath fp = new FleePath(start.position, end.position, searchLength, OnPathComplete);
            fp.fleeStrength  = aimStrength;
            fp.replaceChance = replaceChance;
            fp.spread        = spread;

            p = fp;
        }
        else if (activeDemo == 4)
        {
            ConstantPath constPath = new ConstantPath(start.position, searchLength, OnPathComplete);

            p = constPath;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
        }
    }
Beispiel #8
0
    /** Starts a path specified by PathTypesDemo.activeDemo */
    void DemoPath()
    {
        Path p = null;

        if (activeDemo == DemoMode.ABPath)
        {
            p = ABPath.Construct(start.position, end.position, OnPathComplete);

            if (agents != null && agents.Length > 0)
            {
                List <Vector3> pts = Pathfinding.Util.ListPool <Vector3> .Claim(agents.Length);

                Vector3 avg = Vector3.zero;
                for (int i = 0; i < agents.Length; i++)
                {
                    pts.Add(agents[i].transform.position);
                    avg += pts[i];
                }
                avg /= pts.Count;
                for (int i = 0; i < agents.Length; i++)
                {
                    pts[i] -= avg;
                }

                Pathfinding.PathUtilities.GetPointsAroundPoint(end.position, AstarPath.active.graphs[0] as IRaycastableGraph, pts, 0, 0.2f);
                for (int i = 0; i < agents.Length; i++)
                {
                    if (agents[i] == null)
                    {
                        continue;
                    }

                    agents[i].target.position = pts[i];
                    agents[i].UpdatePath();
                }
            }
        }
        else if (activeDemo == DemoMode.MultiTargetPath)
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == DemoMode.RandomPath)
        {
            RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
            rp.spread      = spread;
            rp.aimStrength = aimStrength;
            rp.aim         = end.position;

            p = rp;
        }
        else if (activeDemo == DemoMode.FleePath)
        {
            FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength = aimStrength;
            fp.spread      = spread;

            p = fp;
        }
        else if (activeDemo == DemoMode.ConstantPath)
        {
            StartCoroutine(CalculateConstantPath());
            p = null;
        }
        else if (activeDemo == DemoMode.FloodPath)
        {
            FloodPath fp = FloodPath.Construct(end.position, null);
            lastFlood = fp;
            p         = fp;
        }
        else if (activeDemo == DemoMode.FloodPathTracer && lastFlood != null)
        {
            FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete);

            p = fp;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
Beispiel #9
0
    public void DemoPath()
    {
        Path path = null;

        if (this.activeDemo == 0)
        {
            path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete));
            if (this.agents != null && this.agents.Length > 0)
            {
                List <Vector3> list = ListPool <Vector3> .Claim(this.agents.Length);

                Vector3 vector = Vector3.zero;
                for (int i = 0; i < this.agents.Length; i++)
                {
                    list.Add(this.agents[i].transform.position);
                    vector += list[i];
                }
                vector /= (float)list.Count;
                for (int j = 0; j < this.agents.Length; j++)
                {
                    List <Vector3> list2;
                    int            index;
                    (list2 = list)[index = j] = list2[index] - vector;
                }
                PathUtilities.GetPointsAroundPoint(this.end.position, AstarPath.active.graphs[0] as IRaycastableGraph, list, 0f, 0.2f);
                for (int k = 0; k < this.agents.Length; k++)
                {
                    if (!(this.agents[k] == null))
                    {
                        this.agents[k].target.position = list[k];
                        this.agents[k].UpdatePath();
                    }
                }
            }
        }
        else if (this.activeDemo == 1)
        {
            MultiTargetPath multiTargetPath = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, new OnPathDelegate(this.OnPathComplete));
            path = multiTargetPath;
        }
        else if (this.activeDemo == 2)
        {
            RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
            randomPath.spread      = this.spread;
            randomPath.aimStrength = this.aimStrength;
            randomPath.aim         = this.end.position;
            path = randomPath;
        }
        else if (this.activeDemo == 3)
        {
            FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
            fleePath.aimStrength = this.aimStrength;
            fleePath.spread      = this.spread;
            path = fleePath;
        }
        else if (this.activeDemo == 4)
        {
            base.StartCoroutine(this.Constant());
            path = null;
        }
        else if (this.activeDemo == 5)
        {
            FloodPath floodPath = FloodPath.Construct(this.end.position, null);
            this.lastFlood = floodPath;
            path           = floodPath;
        }
        else if (this.activeDemo == 6 && this.lastFlood != null)
        {
            FloodPathTracer floodPathTracer = FloodPathTracer.Construct(this.end.position, this.lastFlood, new OnPathDelegate(this.OnPathComplete));
            path = floodPathTracer;
        }
        if (path != null)
        {
            AstarPath.StartPath(path, false);
            this.lastPath = path;
        }
    }
Beispiel #10
0
    IEnumerator UpdatePath()
    {
        while (true)
        {
            if (curState == State.Searching)
            {
                ai.isStopped = false;
                //this.GetComponent<RichAI>().enabled = false;
                if (target != null)
                {
                    if (enemyMode == Mode.Assault)
                    {
                        if (hasDetectedPlayer == false)
                        {
                            if (LastPlayerSighting.position != previousSighting)
                            {
                                personalLastSighting = LastPlayerSighting.position;
                            }

                            Collider[] colliders = Physics.OverlapSphere(this.transform.position, detectionRadius);

                            foreach (Collider collider in colliders)
                            {
                                RunDetection(collider);
                            }

                            previousSighting = LastPlayerSighting.position;

                            if (Time.time > nextSearchTime && (ai.reachedEndOfPath || !ai.hasPath))
                            {
                                trueTarget = null;
                                RandomPath path = RandomPath.Construct(this.transform.position, 20);

                                path.spread = 5;
                                this.GetComponent <Seeker>().StartPath(path);
                            }
                        }
                        else
                        {
                            trueTarget = target;
                        }
                    }
                    else if (enemyMode == Mode.Avoid)
                    {
                        {
                            if (Time.time > nextRunawayTime && Vector3.Distance(this.transform.position, target.transform.position) < 20f)
                            {
                                //Debug.Log("STAY AWAY FROM ME!");

                                Vector3 targetPosition = target.position;

                                int stopGScore = 1000;

                                FleePath path = FleePath.Construct(this.transform.position, targetPosition, stopGScore);
                                path.spread      = 4000;
                                path.aimStrength = 1;


                                Seeker seeker = this.GetComponent <Seeker>();

                                seeker.StartPath(path, GetEscapePath);

                                nextRunawayTime = Time.time * 1.01f;
                            }
                        }
                    }
                }
            }

            if (curState == State.Attacking)
            {
                ai.isStopped = true;
                //var targetRotation = Quaternion.LookRotation(target.position - this.transform.position, Vector3.up);
                //this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRotation, Time.deltaTime * 2.0f);
                this.GetComponent <EnemyAI>().enabled = true;
            }
            yield return(new WaitForEndOfFrame());
        }
    }
 public static AGAstarPath CreateFlee(Vector3 start, Vector3 avoid, int searchLength)
 {
     return(new AGAstarPath(FleePath.Construct(start, avoid, searchLength)));
 }