public override void Execute(Steerable steerable) { base.Execute(steerable); if (targetSteerable) { steerable.AddPursueForce(targetSteerable, strengthMultiplier); } }
/// <summary> /// Makes the steerable pursue the 'targetTransform' instance /// </summary> public override void Execute(Steerable steerable) { base.Execute(steerable); if (targetSteerable) { steerable.AddPursueForce(targetSteerable, strengthMultiplier); } }
public override TaskStatus OnUpdate() { // Cycle through each steering behavior to apply on this GameObject for (int i = 0; i < steeringBehaviors.Length; i++) { // Stores the steering behavior to apply SteeringBehavior steeringBehavior = steeringBehaviors[i]; // Switch the type of the steering behavior and add it to the GameObject switch (steeringBehavior.type) { case SteeringBehaviorType.Seek: steerable.AddSeekForce(steeringBehavior.targetTransform.Value.position, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Arrival: steerable.AddArrivalForce(steeringBehavior.targetTransform.Value.position, steeringBehavior.slowingRadius, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Pursue: steerable.AddPursueForce(steeringBehavior.targetSteerable, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Flee: steerable.AddFleeForce(steeringBehavior.targetTransform.Value.position, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Evade: steerable.AddEvadeForce(steeringBehavior.targetSteerable, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Wander: steerable.AddWanderForce(steeringBehavior.circleDistance, steeringBehavior.circleRadius, steeringBehavior.angleChange, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.ObstacleAvoidance: steerable.AddObstacleAvoidanceForce(steeringBehavior.obstacleAvoidanceForce, steeringBehavior.maxObstacleViewDistance, steeringBehavior.obstacleLayer, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Separation: steerable.AddSeparationForce(steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Alignment: steerable.AddAlignmentForce(steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Cohesion: steerable.AddCohesionForce(steeringBehavior.strengthMultiplier); break; } } // Apply the forces on the steerable that is performing this action steerable.ApplyForces(Time.deltaTime); // If the stopping condition has been met, return success if (stoppingCondition.Complete()) { // Once the stopping condition is met, stop the steerable movement steerable.StopMoving(); return(TaskStatus.Success); } // Else, if the stopping condition has not yet been met else { // Return 'TaskStatus.Running', so that the 'Steer' action can run until the stopping condition is met return(TaskStatus.Running); } }
void FixedUpdate() { // If the stopping condition has been met, stop moving if (stoppingCondition.Complete()) { return; } // Cycle through the steering behaviors to apply on this GameObject for (int i = 0; i < steeringBehaviors.Length; i++) { // Stores the steering behavior to apply SteeringBehavior steeringBehavior = steeringBehaviors[i]; // Switch the type of the steering behavior and add it to the GameObject switch (steeringBehavior.type) { case SteeringBehaviorType.Seek: steerable.AddSeekForce(steeringBehavior.targetTransform.position, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Arrival: steerable.AddArrivalForce(steeringBehavior.targetTransform.position, steeringBehavior.slowingRadius, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Pursue: steerable.AddPursueForce(steeringBehavior.targetSteerable, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Flee: steerable.AddFleeForce(steeringBehavior.targetTransform.position, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Evade: steerable.AddEvadeForce(steeringBehavior.targetSteerable, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Wander: steerable.AddWanderForce(steeringBehavior.circleDistance, steeringBehavior.circleRadius, steeringBehavior.angleChange, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.ObstacleAvoidance: steerable.AddObstacleAvoidanceForce(steeringBehavior.obstacleAvoidanceForce, steeringBehavior.maxObstacleViewDistance, steeringBehavior.obstacleLayer, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.WallAvoidance: steerable.AddWallAvoidanceForce(steeringBehavior.obstacleAvoidanceForce, steeringBehavior.maxObstacleViewDistance, steeringBehavior.obstacleLayer, steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Separation: steerable.AddSeparationForce(steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Alignment: steerable.AddAlignmentForce(steeringBehavior.strengthMultiplier); break; case SteeringBehaviorType.Cohesion: steerable.AddCohesionForce(steeringBehavior.strengthMultiplier); break; } } // Apply the forces on the steerable that is performing this action steerable.ApplyForces(Time.fixedDeltaTime); }