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); }
public override FiniteState CheckState() { // Homer can be set to waiting by the score zone if (_caughtHomer.isWaiting() || _path.Count == 0) { _caughtHomer.SetWaiting(gameObject, _dropPoint); return(_wander); } if ((_caughtHomer.transform.position - this.transform.position).sqrMagnitude < 9) { _steeringController.SetBehaviours( new List <SteeringBehaviour>() { new SteerAvoidBuildings(this.transform), new SteerAlongPath(this.gameObject.transform, _path) } ); } else { _steeringController.SetBehaviours( new List <SteeringBehaviour>() { new SteerAvoidBuildings(this.transform), new SteerToTarget(this.gameObject.transform, _caughtHomer.transform) } ); } _steeringController.Steer(); return(this); }
private void CarControl() { Vector3 input = new Vector3(this.input.x, 0, this.input.y); Vector3 targetPosition = transform.position + transform.TransformDirection(input); steering.Steer(steering.Arrive(targetPosition)); steering.FaceMovementDirection(); }
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); }
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); }
private void FixedUpdate() { Vector3 input = inputController.GetInput(); input.z = input.y; input.y = 0; TargetPosition = transform.position + transform.TransformDirection(input); steering.Steer(steering.Arrive(TargetPosition)); steering.FaceMovementDirection(); }
public override FiniteState CheckState() { if (_homer.GetTooCloseEnemies().Exists((Enemy e) => e.gameObject != _homer.capturer)) { _homer.capturer = null; return(_escape); } _steeringController.Steer(); return(this); }
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); }
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); }