コード例 #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);
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }