public static SidekickFollower SpawnSidekick(Transform lead, LayerMask m) { GameObject g = new GameObject("sidekickFollower"); SidekickFollower sk = g.AddComponent <SidekickFollower>(); GameObject way = new GameObject("waypoint"); way.transform.parent = g.transform; sk.mask = m; sk.Init(lead, way.transform); return(sk); }
public static IEnumerator FollowLeader(AIBlackboard blackboard, ComponentBlackboard components, float speed, int bufferIndex) { blackboard.Waiting = false; components.StopShootingPlayer(); SidekickFollower target = SidekickFollower.SpawnSidekick(blackboard.targetBuffer[bufferIndex], components.controller.visionMask); NavMeshAgent navigation = components.navigation; MecanimLocomotion locomotion = components.locomotion; Transform aiTransform = components.aiObject.transform; navigation.SetDestination(target.Waypoint.position); locomotion.speed = 8; locomotion.lookWhereMoving = true; locomotion.turn = false; locomotion.move = true; yield return(null); while (Vector3.Distance(target.Waypoint.position, aiTransform.position) > 5) { navigation.SetDestination(target.Waypoint.position); components.Navigate(); target.PositionWaypoint(); yield return(new WaitForSeconds(0.1f)); } locomotion.speed = speed; locomotion.lookWhereMoving = true; locomotion.turn = false; locomotion.move = true; yield return(null); while (true) { if (Vector3.Distance(target.Waypoint.position, aiTransform.position) > 1) { navigation.SetDestination(target.Waypoint.position); target.PositionWaypoint(); components.Navigate(); } else { components.StopNavigating(); locomotion.turn = false; locomotion.move = false; } yield return(null); } }