Exemple #1
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (birdAI == null)
     {
         birdAI = animator.GetComponent <BirdAI>();
     }
 }
Exemple #2
0
 //instantiations for script references
 void Start()
 {
     changeBG     = GameObject.FindGameObjectWithTag("Background").GetComponent <ChangeBackground> ();
     player       = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>();
     playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>();
     camera       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraControl>();
     platforms    = GameObject.FindGameObjectWithTag("Ground").GetComponent <SpawnPlatforms>();
     birds        = GameObject.FindGameObjectWithTag("Bird").GetComponent <BirdAI>();
     enemy1       = GameObject.FindGameObjectWithTag("Enemy1").GetComponent <Enemy1AI>();
 }
Exemple #3
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (birdAI == null)
        {
            birdAI = animator.GetComponent <BirdAI>();
        }
        if (navAgent == null)
        {
            navAgent = animator.GetComponent <NavMeshAgent>();
        }

        navAgent.enabled = true;
    }
Exemple #4
0
    public void RemoveBird(GameObject bird)
    {
        BirdAI ba = bird.GetComponent <BirdAI>();

        //find the spot this bird occupies and set it to unoccupied
        occupied[ba.RestPosIdx] = false;

        //remove this bird from this tree's bird list, and decrease the count
        birds.Remove(bird);
        birdCount -= 1;

        //TODO: make bird fly away (animation and movement)
        //ba.FlyAway();
    }
    List <Transform> GetNearbyObjects(BirdAI agent)
    {
        List <Transform> context = new List <Transform>();

        Collider[] contextColliders = Physics.OverlapSphere(agent.transform.position, neighbourRadius);

        foreach (Collider c in contextColliders)
        {
            if (c != agent.AgentCollider)
            {
                context.Add(c.transform);
            }
        }
        return(context);
    }
Exemple #6
0
    public void RemoveABird(GameObject bird)
    {
        BirdAI ba = bird.GetComponent <BirdAI>();

        //find the tree this bird is on
        GrownTree gt = GrownTrees.Concat(OccupiedTrees).ToList().Find(t => t.tree == ba.TargetTree.tree);

        gt.RemoveBird(bird);

        if (OccupiedTrees.Contains(gt))
        {
            OccupiedTrees.Remove(gt);
            GrownTrees.Add(gt);
        }
    }
Exemple #7
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (birdAI == null)
        {
            birdAI = animator.GetComponent <BirdAI>();
        }
        if (navAgent == null)
        {
            navAgent = animator.GetComponent <NavMeshAgent>();
        }

        navAgent.enabled = true;
        targetDest       = birdAI.TrapPosition;
        navAgent.SetDestination(targetDest);
    }
Exemple #8
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (birdAI == null)
        {
            birdAI = animator.GetComponent <BirdAI>();
        }
        if (navAgent == null)
        {
            navAgent = animator.GetComponent <NavMeshAgent>();
        }

        waitTime = Random.Range(3f, 6f);
        poopTime = Random.Range(5f, 10f);

        birdAI.TargetTree.birdOnTree += 1;
    }
    // Start is called before the first frame update
    void Start()
    {
        squareMaxSpeed        = maxSpeed * maxSpeed;
        squareNeighbourRadius = neighbourRadius * neighbourRadius;
        squareAvoidanceRadius = squareNeighbourRadius * avoidanceRadiusMultiplier * avoidanceRadiusMultiplier;

        for (int i = 0; i < startingCount; i++)
        {
            BirdAI newAgent = Instantiate(
                agentPrefab,
                Random.insideUnitSphere * startingCount * agentDensity,
                Quaternion.Euler(Vector3.forward * Random.Range(0f, 360f)),
                transform
                );

            newAgent.name = "Agent " + i;
            agents.Add(newAgent);
        }
    }
Exemple #10
0
    void DeployBird(GrownTree tree)
    {
        //find a spot that is not occupied
        int idx = -1;

        for (int i = 0; i < tree.occupied.Length; i++)
        {
            if (!tree.occupied[i])
            {
                idx = i;
            }
        }

        //if all occupied, return
        if (idx == -1)
        {
            return;
        }

        //instantiate a bird
        GameObject bird = Instantiate(birdPrefab);

        //set this bird's target position to the rest spot position, target tree to this tree
        BirdAI ba = bird.GetComponent <BirdAI>();

        ba.TargetRestPosition = tree.tree.transform.position + tree.restPositions[idx];
        ba.RestRotation       = tree.restRotations[idx];
        ba.TargetTree         = tree;
        ba.RestPosIdx         = idx;

        //increase this tree's birdcount and add this bird to this tree
        tree.birdCount++;
        tree.birds.Add(bird);
        tree.occupied[idx] = true;

        //if this tree's birdcount reaches max, move this tree from grown list to occupied list
        if (tree.birdCount >= tree.maxBird)
        {
            GrownTrees.Remove(tree);
            OccupiedTrees.Add(tree);
        }
    }
Exemple #11
0
 void Start()
 {
     rb = GetComponent <Rigidbody>();
     ba = GetComponent <BirdAI>();
 }
 public abstract Vector3 CalculateMove(BirdAI aiAgent, List <Transform> context, Flock flock);