bool ShouldStop()
    {
        // If no destination has been set, then always stop
        if (float.IsPositiveInfinity(ai.destination.x))
        {
            return(true);
        }

        var thisAgent = rvo.rvoAgent;
        var radius    = (ai.destination - ai.position).magnitude;

        var radius2 = thisAgent.Radius * 5;

        if (radius > radius2)
        {
            // If the agent is far away from the destination then do a faster check around the destination first.
            if (AgentDensityInCircle(rvo.To2D(ai.destination), radius2) < MaximumCirclePackingDensity * densityFraction)
            {
                return(false);
            }
        }

        var result = AgentDensityInCircle(rvo.To2D(ai.destination), radius) > MaximumCirclePackingDensity * densityFraction;

        //Pathfinding.Util.Draw.Debug.CircleXZ(ai.destination, radius, result ? Color.green : Color.red);

        timer2 = Mathf.Lerp(timer2, result ? 1 : 0, Time.deltaTime);
        return(result && timer2 > 0.1f);
    }
        public void OnPathComplete(Path _p)
        {
            Debug.LogError(gameObject.name);

            ABPath p = _p as ABPath;

            canSearchAgain = true;

            if (path != null)
            {
                path.Release(this);
            }
            path = p;
            p.Claim(this);

            if (p.error)
            {
                wp         = 0;
                vectorPath = null;
                return;
            }


            Vector3 p1 = p.originalStartPoint;
            Vector3 p2 = transform.position;

            p1.y = p2.y;
            float d = (p2 - p1).magnitude;

            wp = 0;

            vectorPath = p.vectorPath;
            Vector3 waypoint;

            if (moveNextDist > 0)
            {
                for (float t = 0; t <= d; t += moveNextDist * 0.6f)
                {
                    wp--;
                    Vector3 pos = p1 + (p2 - p1) * t;

                    do
                    {
                        wp++;
                        waypoint = vectorPath[wp];
                    } while (controller.To2D(pos - waypoint).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                }
            }
        }
Example #3
0
        public void OnPathComplete(Path _p)
        {
            //Good Game

            /*if(!_p.error)
             * {
             *  for (int i = 0; i < _p.vectorPath.Count; i++)
             *  {
             *      Debug.Log(gameObject.name + "--first--" + i + "--" + IntMath.Int3s2Vector3s(_p.vectorPath)[i]);
             *  }
             * }*/
            ABPath p = _p as ABPath;

            canSearchAgain = true;

            if (path != null)
            {
                path.Release(this);
            }
            path = p;
            p.Claim(this);

            if (p.error)
            {
                wp         = 0;
                vectorPath = null;
                return;
            }


            //Good Game

            /*Vector3 p1 = (Vector3)p.originalStartPoint;
             *          Vector3 p2 = transform.position;*/
            VInt3 p1 = p.originalStartPoint;
            VInt3 p2 = (VInt3)transform.position;

            p1.y = p2.y;
            //GG
            //float d = (p2 - p1).magnitude;
            float d = ((Vector3)(p2 - p1)).magnitude;

            wp = 0;

            //Good Game
            vectorPath = p.vectorPath;
            //vectorPath = IntMath.Int3s2Vector3s(p.vectorPath);
            for (int i = 0; i < vectorPath.Count; i++)
            {
                Debug.Log(gameObject.name + "--path count--" + i + "--" + vectorPath[i]);
            }
            //Good Game
            //Vector3 waypoint;
            VInt3 waypoint;

            if (moveNextDist > 0)
            {
                for (float t = 0; t <= d; t += moveNextDist * 0.6f)
                {
                    wp--;
                    //Good Game
                    //Vector3 pos = p1 + (p2-p1)*t;
                    VInt3 pos = p1 + (p2 - p1) * t;

                    do
                    {
                        wp++;
                        waypoint = vectorPath[wp];
                        //Debug.Log($"--waypoint--{gameObject.name}--{((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude}--{moveNextDist * moveNextDist}");
                    }
                    //Good Game
                    //while (controller.To2D(pos - waypoint).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1);
                    //while (((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                    while (controller.To2D((pos - waypoint)).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                }
                //Debug.Log($"--waypoint index--{gameObject.name}--{wp}");
            }
            //GG Test
            //wp = 2;
        }