Example #1
0
        public override void GetMaps(out DangerMap dangerMap, out InterestMap interestMap)
        {
            interestMap = new InterestMap(0f, _contextSteering.SteeringResolution);
            dangerMap   = new DangerMap(0f, _contextSteering.SteeringResolution);

            if (_contextSteering.TargetData == null)
            {
                return;
            }

            Vector3 toTarget = _contextSteering.TargetData.GetDirectionToTarget(_mTransform);
            float   distance = _contextSteering.TargetData.GetColliderDistanceFromTarget(transform);

            for (int i = 0; i < ContextMap.defaultDirections[_contextSteering.SteeringResolution].Length; i++)
            {
                float dot = Vector3.Dot(ContextMap.defaultDirections[_contextSteering.SteeringResolution][i], toTarget);

                if (dot >= 0)
                {
                    interestMap.InsertValue(i, dot * Mathf.Clamp(distance - stoppingDistance, 0f, 1f), (int)_contextSteering.SteeringResolution / 8);
                }
            }

            interestMap = (InterestMap)ContextMap.Combine(interestMap, _lastFrameInterest, interestLoseRateo);

            _lastFrameInterest = interestMap;

            if (!debug)
            {
                return;
            }

            interestMap.DebugMap(transform.position);
            dangerMap.DebugMap(transform.position);
        }
Example #2
0
        public static Vector3 CalculateDirection(InterestMap interestMap, DangerMap dangerMap)
        {
            Vector3[][] safeDirections = new Vector3[interestMap.Map.Length][];

            int r = 0;
            int c = 0;

            for (int i = 0; i < interestMap.Map.Length; i++)
            {
                if (IsSafeDirection(interestMap.Map[i], dangerMap.Map[i]))
                {
                    if (c == 0)
                    {
                        safeDirections[r] = new Vector3[interestMap.Map.Length];
                    }

                    safeDirections[r][c] = interestMap.Map[i].normalized * Mathf.Clamp(interestMap.Map[i].magnitude - dangerMap.Map[i].magnitude, 0f, 1f);
                    c++;
                }
                else
                {
                    c = 0;
                    r++;
                }
            }

            Vector3[] directions = safeDirections.
                                   Where(entry => entry != null).
                                   OrderByDescending(entry => entry.Aggregate((acc, next) => acc + next).magnitude).
                                   FirstOrDefault();

            return(directions != null && directions.Length > 0 ? directions.Aggregate((acc, next) => acc + next).normalized : Vector3.zero);
        }
        public override void GetMaps(out DangerMap dangerMap, out InterestMap interestMap)
        {
            interestMap = new InterestMap(0f, _contextSteering.SteeringResolution);
            dangerMap   = new DangerMap(0f, _contextSteering.SteeringResolution);

            if (_groupManager == null)
            {
                return;
            }

            if (_contextSteering.TargetData.Target == null)
            {
                return;
            }

            // Group Number (4) hardcoded.
            // Group enum has 6 values so we can't use it
            float step = 360f / 4;

            Vector3 targetPosition = _contextSteering.TargetData.Target.position + _contextSteering.TargetData.Target.forward * _currentDecenter +
                                     Quaternion.Euler(0f, step * (int)_groupManager.ThisGroupName, 0f) *
                                     (Vector3.forward * (_currentCloseness + _contextSteering.TargetData.Target.GetComponent <CapsuleCollider>().radius));

            Vector3 toDesiredPosition = (targetPosition - transform.position).normalized;

            _currentDistance = Vector3.Distance(transform.position, targetPosition);

            // TODO :- Find better solution
            _needsUpdate = false;

            for (int i = 0; i < ContextMap.defaultDirections[_contextSteering.SteeringResolution].Length; i++)
            {
                float dot = Vector3.Dot(ContextMap.defaultDirections[_contextSteering.SteeringResolution][i],
                                        toDesiredPosition);
                if (dot >= 0)
                {
                    interestMap.InsertValue(i, dot * Mathf.Clamp(_currentDistance - _currentStoppingDistance, 0f, 1f), (int)_contextSteering.SteeringResolution / 8);
                }
            }

            interestMap = (InterestMap)ContextMap.Combine(interestMap, _lastFrameInterest, interestLoseRateo);
            dangerMap   = (DangerMap)ContextMap.Combine(dangerMap, _lastFrameDanger, dangerLoseRateo);

            _lastFrameInterest = interestMap;
            _lastFrameDanger   = dangerMap;

            if (!debug)
            {
                return;
            }

            interestMap.DebugMap(transform.position);
            dangerMap.DebugMap(transform.position);
        }
Example #4
0
        public override void GetMaps(out DangerMap dangerMap, out InterestMap interestMap)
        {
            interestMap = new InterestMap(0f, _contextSteering.SteeringResolution);
            dangerMap   = new DangerMap(0f, _contextSteering.SteeringResolution);

            Vector3 forward = transform.forward;

            for (int i = 0; i < ContextMap.defaultDirections[_contextSteering.SteeringResolution].Length; i++)
            {
                if (!TestDirection(out RaycastHit hitInfo, i))
                {
                    continue;
                }

                if (hitInfo.transform.root == transform)
                {
                    continue;
                }

                float dot = Mathf.Abs(Vector3.Dot(ContextMap.defaultDirections[_contextSteering.SteeringResolution][i],
                                                  forward));
                float distance = Vector3.Distance(hitInfo.point, _collider.ClosestPoint(hitInfo.point));

                dangerMap.InsertValue(i, Mathf.Min(k / (distance * distance), dot), (int)_contextSteering.SteeringResolution / 8);
                interestMap.InsertValue(interestMap.GetOppositeDirection(i), Mathf.Min(k / (distance * distance), dot), (int)_contextSteering.SteeringResolution / 8);

                // dangerMap.InsertValue(i,Mathf.Max(dot/distance,1f),(int)_contextSteering.SteeringResolution/8);
                // interestMap.InsertValue(dangerMap.GetOppositeDirection(i),Mathf.Max(dot/distance,1f),(int)_contextSteering.SteeringResolution/8);
            }

            interestMap = (InterestMap)ContextMap.Combine(interestMap, _lastFrameInterest, interestLoseRateo);
            dangerMap   = (DangerMap)ContextMap.Combine(dangerMap, _lastFrameDanger, dangerLoseRateo);

            _lastFrameInterest = interestMap;
            _lastFrameDanger   = dangerMap;

            if (!debug)
            {
                return;
            }

            interestMap.DebugMap(transform.position);
            dangerMap.DebugMap(transform.position);
        }
        public override void GetMaps(out DangerMap dangerMap, out InterestMap interestMap)
        {
            interestMap = new InterestMap(0f, _contextSteering.SteeringResolution);
            dangerMap   = new DangerMap(0f, _contextSteering.SteeringResolution);

            if (_currentArena == null)
            {
                return;
            }

            Vector3 toDesiredPosition = (_currentArena.transform.position - transform.position).normalized;
            float   distance          = Vector3.Distance(transform.position, _currentArena.transform.position);

            for (int i = 0; i < ContextMap.defaultDirections[_contextSteering.SteeringResolution].Length; i++)
            {
                float dot = Vector3.Dot(ContextMap.defaultDirections[_contextSteering.SteeringResolution][i],
                                        toDesiredPosition);
                if (dot >= 0)
                {
                    //interestMap.InsertValue(i, Mathf.Min((distance * distance) / k,dot), (int)_contextSteering.SteeringResolution/8);
                    dangerMap.InsertValue(dangerMap.GetOppositeDirection(i), Mathf.Min((distance * distance) / k, dot), (int)_contextSteering.SteeringResolution / 8);
                }
            }

            //interestMap = (InterestMap) ContextMap.Combine(interestMap, _lastFrameInterest, interestLoseRateo);
            dangerMap = (DangerMap)ContextMap.Combine(dangerMap, _lastFrameDanger, dangerLoseRateo);

            _lastFrameInterest = interestMap;
            _lastFrameDanger   = dangerMap;

            if (!debug)
            {
                return;
            }

            interestMap.DebugMap(transform.position);
            dangerMap.DebugMap(transform.position);
        }
Example #6
0
        public static void Combine(out InterestMap finalInterest, out DangerMap finalDanger, List <InterestMap> interestMaps, List <DangerMap> dangerMaps)
        {
            InterestMap combinedInterest = interestMaps[0];
            DangerMap   combinedDanger   = dangerMaps[0];

            for (int j = 1; j < interestMaps.Count; j++)
            {
                for (int i = 0; i < interestMaps[j].Map.Length; i++)
                {
                    if (!(combinedInterest.Map[i].magnitude > interestMaps[j].Map[i].magnitude))
                    {
                        combinedInterest.Map[i] = interestMaps[j].Map[i];
                    }

                    if (!(combinedDanger.Map[i].magnitude > dangerMaps[j].Map[i].magnitude))
                    {
                        combinedDanger.Map[i] = dangerMaps[j].Map[i];
                    }
                }
            }

            finalInterest = combinedInterest;
            finalDanger   = combinedDanger;
        }
Example #7
0
 public abstract void GetMaps(out DangerMap dangerMap, out InterestMap interestMap);
Example #8
0
 private void Start()
 {
     _lastFrameInterest = new InterestMap(0f, _contextSteering.SteeringResolution);
     _lastFrameDanger   = new DangerMap(0f, _contextSteering.SteeringResolution);
 }