public override SteeringOutput GetOutput()
        {
            if (!_target.isSet)
            {
                return(new SteeringOutput());
            }

            SteeringOutput output = PrimitiveBehavior.Pursue(_character,
                                                             _target.body,
                                                             _properties);

            output.StopRotation = true;

            return(output);
        }
        public override SteeringOutput GetOutput()
        {
            if (!_target.isSet)
            {
                return(new SteeringOutput());
            }

            // todo : make an escape more intelligent (using pathfinding)

            SteeringOutput output = PrimitiveBehavior.Flee(_character, _target.position, _properties);

            output.StopRotation = true;

            return(output);
        }
Beispiel #3
0
        public override SteeringOutput GetOutput()
        {
            if (!_target.isSet)
            {
                return(new SteeringOutput());
            }

            SteeringOutput output = PrimitiveBehavior.Face(_character,
                                                           _target.position,
                                                           _properties);

            output.StopVelocity = true;

            return(output);
        }
        public override SteeringOutput GetOutput()
        {
            if (!_target.isSet)
            {
                return(new SteeringOutput());
            }

            // check if the character has reached the targetNode
            if (_currentNodeIndex < _smoothPath.Count && _smoothPath.Count > 0)
            {
                Vector2i?coord = Map.instance.navGrid.GetCoordAt(_character.position);

                if (!coord.HasValue)
                {
                    Debug.LogWarning("The character exit the map");
                    _smoothPath.Clear();
                    _currentNodeIndex = 0;

                    return(new SteeringOutput());
                }

                if (_currentNodeIndex < 0 || _currentNodeIndex >= _smoothCoordPath.Count)
                {
                    Debug.Break();
                }

                if (_smoothCoordPath[_currentNodeIndex] == coord.Value)
                {
                    _currentNodeIndex++;
                }
            }

            Vector2 targetPosition;

            SteeringOutput output;

            if (_currentNodeIndex >= _smoothPath.Count || _smoothPath.Count == 0)
            {
                targetPosition = _target.position;

                if (TargetIsTheEnd)
                {
                    output = PrimitiveBehavior.Arrive(_character,
                                                      targetPosition,
                                                      _properties);
                }
                else
                {
                    output = PrimitiveBehavior.Seek(_character, targetPosition, _properties);
                }
            }
            else
            {
                targetPosition = _smoothPath[_currentNodeIndex];

                output = PrimitiveBehavior.Seek(_character, targetPosition, _properties);
            }

            output.StopRotation = true;

            return(output);
        }