Beispiel #1
0
        protected override Vector2 DoForceCalculation()
        {
            if (path2D == null)
            {
                return(Vector2.zero);
            }

            float speedPerFrame = Controller.MaxSpeed * Time.fixedDeltaTime;

            if (!finished && Vector2.Distance(transform.position, path2D[curWaypoint]) <= speedPerFrame)
            {
                curWaypoint = (curWaypoint + 1) % path2D.Length;

                if (!loop && curWaypoint == path2D.Length - 1)      //End of path
                {
                    finished = true;
                }
            }

            if (finished)
            {
                return(arrive.CalculateForce(path2D[curWaypoint]));
            }

            return(seek.CalculateForce(path2D[curWaypoint]));
        }
Beispiel #2
0
        protected override Vector2 DoForceCalculation()
        {
            if (target == null)
            {
                return(Vector2.zero);
            }

            Vector2 toTarget = target.transform.position - transform.position;

            float relativeHeading = Vector2.Dot(transform.up, target.transform.up);

            if (Vector2.Dot(toTarget, transform.up) > 0 &&
                relativeHeading < -0.95)
            {
                return(seek.CalculateForce(target.position));
            }

            float lookAheadTime = toTarget.magnitude / (Controller.MaxSpeed + target.velocity.magnitude);

            return(seek.CalculateForce(target.position + target.velocity * lookAheadTime));
        }
Beispiel #3
0
        protected override Vector2 DoForceCalculation()
        {
            wanderTarget += new Vector2(
                Random.Range(-1.0f, 1.0f) * wanderJitter,
                Random.Range(-1.0f, 1.0f) * wanderJitter);
            wanderTarget.Normalize();
            wanderTarget *= wanderRadius;

            Vector2 targetLocal = wanderTarget + new Vector2(0.0f, wanderDistance);

            Vector2 targetWorld = transform.localToWorldMatrix.MultiplyPoint(targetLocal);

            return(seek.CalculateForce(targetWorld));
        }
Beispiel #4
0
        protected override Vector2 DoForceCalculation()
        {
            Vector2 centerOfMass  = Vector2.zero;
            Vector2 steeringForce = Vector2.zero;

            for (int i = 0; i < neighbours.NeighbourCount; i++)
            {
                Collider2D neighbour = neighbours.GetNeighbour(i);

                centerOfMass += (Vector2)neighbour.transform.position;
            }

            if (neighbours.NeighbourCount > 0)
            {
                centerOfMass /= neighbours.NeighbourCount;

                steeringForce = seek.CalculateForce(centerOfMass);
            }

            return(steeringForce);
        }