コード例 #1
0
        protected override Vector2 DoForceCalculation()
        {
            if (pursuer == null)
            {
                return(Vector2.zero);
            }

            int layerMask     = LayerMask.GetMask(obstacleLayer);
            int obstacleCount = GetNearbyObjects(maxHideDistance, obstaclesInRange, layerMask);

            float   distanceToNearest = float.MaxValue;
            Vector2 nearest           = Vector2.zero;
            bool    validPosExists    = false;

            for (int i = 0; i < obstacleCount; i++)
            {
                Vector2 hidePos  = GetHidingPosition(obstaclesInRange[i]);
                float   distance = Vector2.Distance(transform.position, hidePos);
                if (distance < distanceToNearest)
                {
                    distanceToNearest = distance;
                    nearest           = hidePos;
                    validPosExists    = true;
                }
            }

            if (validPosExists)
            {
                return(evade.CalculateForce());
            }

            return(arrive.CalculateForce(nearest));
        }
コード例 #2
0
        protected override Vector2 DoForceCalculation()
        {
            if (leader == null)
            {
                return(Vector2.zero);
            }

            Vector2 worldOffsetPos = leader.transform.localToWorldMatrix.MultiplyPoint(offsetPos);
            Vector2 toOffset       = worldOffsetPos - (Vector2)transform.position;

            float lookAheadTime = toOffset.magnitude / (Controller.Speed - leader.velocity.magnitude);

            return(arrive.CalculateForce(worldOffsetPos + leader.velocity * lookAheadTime));
        }