// 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;
    }
Exemple #2
0
    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);
    }
Exemple #3
0
    public void SetLeader()
    {
        if (herdAnimals.Count <= 0)
        {
            parent.RemoveHerd(this);
            return;
        }

        _herdLeader = herdAnimals[0];
        herdAnimals[0].SetLeaderStatus(true);

        _currentHerdLocation = _herdLeader.transform;
    }
Exemple #4
0
    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();
    }
Exemple #5
0
    public void RemoveHerdAnimal(BaseHerdAnimal herdAnimal)
    {
        herdAnimals.Remove(herdAnimal);

        //Debug.Log("Herd animals count: " + herdAnimals.Count);
    }