private void boarding() { loadCooldown -= Time.deltaTime; if (loadCooldown < 0) { loadCooldown = interval; if (unloadIndex < menCount) { men[unloadIndex++].setMatch(transporter.transform.position); } foreach (var man in men.Where((x, i) => i < unloadIndex)) { if (man.reachedDestination) { man.setActive(false); } } if (men.All(x => !x.active)) { behaviour = InfantryBehaviourState.Nothing; } } }
private void setRingFormation() { var radius = .8f; List <Vector3> destinations = new List <Vector3>(); for (int i = 0; i < menCount; i++) { var offset = Quaternion.AngleAxis(360 * i / (menCount), Vector3.up) * (radius * Vector3.forward) + destination; destinations.Add(offset); } men.ConvertAll(x => x as Matchable <Vector3>).Match(destinations); behaviour = InfantryBehaviourState.GettingIntoFormation; }
public void unload(Vector3 pos, Vector3 rally) { enabled = true; initialize(); transform.position = rally; destination = rally; foreach (var man in men) { man.gameObject.transform.position = pos; man.gameObject.SetActive(false); } setRingFormation(); unloadIndex = 0; behaviour = InfantryBehaviourState.Unloading; }
public void unload(Vector3 pos, Vector3 rally) { enabled = true; initialize(); transform.position = pos; Pathfinder.SetPath(rally, MoveCommandType.Slow); foreach (var man in men) { man.gameObject.transform.position = pos; man.gameObject.SetActive(false); } setRingFormation(); unloadIndex = 0; behaviour = InfantryBehaviourState.Unloading; }
private void setLineFormation() { var seperation = .4f; List <Vector3> destinations = new List <Vector3>(); var left = Quaternion.AngleAxis(-Mathf.Rad2Deg * finalHeading, Vector3.up) * (seperation * Vector3.forward); for (int i = 0; i < menCount; i++) { var offset = transform.position + left * (i - (menCount - 1) / 2f); destinations.Add(offset); } men.ConvertAll(x => x as Matchable <Vector3>).Match(destinations); behaviour = InfantryBehaviourState.GettingIntoFormation; }
private void getIntoFormation() { if (reachedDestination()) { men.ForEach(x => x.fixFormationOffset(transform.position)); if (gotDestination) { moveToDestination(); } else { ordersDone = true; behaviour = InfantryBehaviourState.Nothing; } } }
// Update is called once per frame void Update() { base.Update(); switch (behaviour) { case InfantryBehaviourState.Boarding: boarding(); break; case InfantryBehaviourState.WalkToTransport: updatePosition(); destination = transporter.getRallyPoint(); if (reachedDestination()) { behaviour = InfantryBehaviourState.Boarding; } else { men.ForEach(x => x.setDestination(destination)); } break; case InfantryBehaviourState.Unloading: unloading(); getIntoFormation(); break; case InfantryBehaviourState.GettingIntoFormation: updatePosition(); getIntoFormation(); break; case InfantryBehaviourState.MoveToWaypoint: updatePosition(); if (reachedDestination()) { setFormation(Formation.Ring); ordersDone = true; } break; case InfantryBehaviourState.Nothing: updatePosition(); break; } //WRONG }
public void setTransportTarget(TransporterBehaviour transport) { if (transport == null) { destination = transform.position; setRingFormation(); } else { transporter = transport; destination = transporter.getRallyPoint(); men.ForEach(x => x.fixFormationOffset(transform.position)); men.ForEach(x => x.setDestination(destination)); //gotDestination = false; behaviour = InfantryBehaviourState.WalkToTransport; } }
public void setTransportTarget(TransporterBehaviour transport) { if (transport == null) { Pathfinder.SetPath(Pathfinder.NoPosition, MoveCommandType.Fast); setRingFormation(); } else { transporter = transport; Pathfinder.SetPath(transporter.getRallyPoint(), MoveCommandType.Fast); men.ForEach(x => x.fixFormationOffset(transform.position)); men.ForEach(x => x.setDestination(Pathfinder.GetDestination())); //gotDestination = false; behaviour = InfantryBehaviourState.WalkToTransport; } }
private void moveToDestination() { men.ForEach(x => x.setDestination(destination)); behaviour = InfantryBehaviourState.MoveToWaypoint; gotDestination = false; }
private void moveToDestination() { men.ForEach(x => x.setDestination(Pathfinder.GetDestination())); behaviour = InfantryBehaviourState.MoveToWaypoint; }