Ejemplo n.º 1
0
    public override FiniteState CheckState()
    {
        float sqrMag = (target.transform.position - this.transform.position).sqrMagnitude;

        if (sqrMag < distanceCatchHomer * distanceCatchHomer)
        {
            _return.CreateNewPath(target);

            return(_return);
        }
        else if (sqrMag < distanceToSteerToHomer * distanceToSteerToHomer)
        {
            _steeringController.SetBehaviours(
                new List <SteeringBehaviour>()
            {
                new SteerAvoidBuildings(this.transform),
                new SteerToTarget(this.transform, target.transform)
            }
                );
        }
        else
        {
            List <Vector3> path = _pathFinder.FindPath(
                this.transform.position,
                target.transform.position                // TODO try to move ahead of homer homervelocitynormalized * distancebetweenhomerandmarge / margespeed
                );

            // If is possible Marge is in a position where a path cannot be determined.
            // If this happens move Marge a little bit and try again
            if (path.Count > 0)
            {
                _steeringController.SetBehaviours(
                    new List <SteeringBehaviour>()
                {
                    new SteerAvoidBuildings(this.transform),
                    new SteerAlongPath(this.transform, path)
                }
                    );
            }
            else
            {
                _steeringController.SetBehaviours(
                    new List <SteeringBehaviour>()
                {
                    new SteerAvoidBuildings(this.transform),
                    new SteerWanderXZ(this.transform)
                }
                    );
            }
        }

        _steeringController.Steer();

        return(this);
    }
Ejemplo n.º 2
0
    public override FiniteState CheckState()
    {
        if (_homer.EnemyTooClose())
        {
            return(_escape);
        }

        List <Homer> homersInFlockingRange = _homer.GetHomersCloseEnoughToFlock().FindAll(h => h.capturer == null);

        if (homersInFlockingRange.Count == 0)
        {
            return(_wander);
        }

        _steeringController.SetBehaviours(
            homersInFlockingRange.ConvertAll <SteeringBehaviour>(
                (h) => new SteerToTarget(this.gameObject.transform, h.transform)
                )
            );

        _steeringController.AddBehaviours(
            _homer.GetTooCloseHomers().ConvertAll <SteeringBehaviour>(
                (h) => new SteerFromTarget(this.gameObject.transform, h.transform)
                )
            );

        _steeringController.AddBehaviours(new SteerAvoidBuildings(this.transform));

        _steeringController.Steer();

        return(this);
    }
Ejemplo n.º 3
0
    public override FiniteState CheckState()
    {
        Homer h = _marge.GetClosestHomer();

        if (h != null)
        {
            _catch.target = h;

            return(_catch);
        }

        if (_path == null || _path.Count == 0)
        {
            CreateNewPath();

            // If is possible Marge is in a position where a path cannot be determined.
            // If this happens move Marge a little bit and try again
            if (_path == null || _path.Count == 0)
            {
                _steeringController.SetBehaviours(
                    new List <SteeringBehaviour> ()
                {
                    new SteerAvoidBuildings(transform),
                    new SteerWanderXZ(transform)
                }
                    );

                _steeringController.Steer();

                return(this);
            }
        }

        _steeringController.SetBehaviours(
            new List <SteeringBehaviour>()
        {
            new SteerAvoidBuildings(transform),
            new SteerAlongPath(transform, _path)
        }
            );

        _steeringController.Steer();

        return(this);
    }
Ejemplo n.º 4
0
    public void CreateNewPath(Homer homer)
    {
        _caughtHomer = homer;
        homer.SetCaught(this.gameObject);

        _path = _pathFinder.FindPath(
            this.gameObject.transform.position,
            _dropPoint.position
            );

        _steeringController.SetBehaviours(
            new List <SteeringBehaviour>()
        {
            new SteerAvoidBuildings(this.transform),
            new SteerAlongPath(this.gameObject.transform, _path)
        }
            );
    }
Ejemplo n.º 5
0
 public void StartFollowing(Transform target)
 {
     _steeringController.SetBehaviours(
         new List <SteeringBehaviour>()
     {
         new SteerAvoidBuildings(this.transform),
         new SteerToTarget(this.transform, target.transform)
     }
         );
 }
Ejemplo n.º 6
0
    public override FiniteState CheckState()
    {
        List <Enemy> tooCloseEnemies = _homer.GetTooCloseEnemies();

        if (tooCloseEnemies.Count == 0)
        {
            return(_wander);
        }

        _steeringController.SetBehaviours(
            tooCloseEnemies.ConvertAll <SteeringBehaviour>(
                (e) => new SteerFromTarget(this.gameObject.transform, e.transform)
                )
            );

        _steeringController.AddBehaviours(new SteerAvoidBuildings(this.transform));

        _steeringController.Steer();

        return(this);
    }
Ejemplo n.º 7
0
    public override FiniteState CheckState()
    {
        if (_homer.EnemyTooClose())
        {
            return(_escape);
        }

        if (_homer.HomerCloseEnoughToFlock())
        {
            return(_flock);
        }

        _steeringController.SetBehaviours(
            new List <SteeringBehaviour>()
        {
            new SteerAvoidBuildings(this.transform),
            new SteerWanderXZ(this.gameObject.transform)
        }
            );

        _steeringController.Steer();

        return(this);
    }