// TODO: Follow the leader based on the Boids alghoritm private void FollowLeader() { BaseHerdAnimal myLeader = _myHerd._herdLeader; Quaternion rotation = Allign(); Vector3 movement = Cohesion(myLeader.transform.position); transform.position += movement; transform.rotation = rotation; }
public void SpawnHerd(string herdAnimalID, Vector3 worldLocation, int herdSize) { if (playerTransform == null) { playerTransform = GameAccesPoint.Instance.mainGameState._playerController._playerTransform; } BaseHerdAnimal animalType = (BaseHerdAnimal)parent._gameItemDatabase.GetItem(herdAnimalID); Herd newHerd = new Herd(this, animalType, worldLocation, herdSize); herds.Add(newHerd); }
public void SetLeader() { if (herdAnimals.Count <= 0) { parent.RemoveHerd(this); return; } _herdLeader = herdAnimals[0]; herdAnimals[0].SetLeaderStatus(true); _currentHerdLocation = _herdLeader.transform; }
public Herd(HerdHandler parent, BaseHerdAnimal animalType, Vector3 worldLocation, int herdSize) { this.parent = parent; _startLocation = worldLocation; for (int i = 0; i < herdSize; i++) { Vector3 spawnPos = new Vector3(worldLocation.x + i + 1, worldLocation.y, worldLocation.z); BaseHerdAnimal newHerdAnimal = Object.Instantiate(animalType); newHerdAnimal.OnCreate(spawnPos, Quaternion.identity); newHerdAnimal.AssignHerd(this); herdAnimals.Add(newHerdAnimal); } SetLeader(); }
public void RemoveHerdAnimal(BaseHerdAnimal herdAnimal) { herdAnimals.Remove(herdAnimal); //Debug.Log("Herd animals count: " + herdAnimals.Count); }