Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Score, Enemies, and Game State Create Enemy Navigation and AI

Making the Bird AI a little more complicated?

I wanted to make the game more challenging by making the Bird move faster as more flies are collected. I noticed that acceleration was the main variable that changed speed and turn direction, so I wrote:

float acceleration = birdAgent.acceleration + ScoreCounter.score;

and

birdAnimator.SetFloat("Acceleration",acceleration);

but the console said that "Acceleration wasn't recognized.

I next tried to edit solely the speed by writing:

float speed = birdAgent.velocity.magnitude + 100*ScoreCounter.score;

But nothing changed when I played the game.

What am I doing wrong/what can I do?

2 Answers

I will have to take a look at some of this code when I get home. I would approach this by having a if loop which runs when a user collects a fly, and then do speed++.

You probably have already figured this out by now, but I will provide my way of doing it for anyone else who ends up being interested.

I put this is BirdMovement.cs:

Add this at the top of the code below the class name and above the Start method:

public static NavMeshAgent speedIncreaser;

Add this in the Start method:

speedIncreaser = GetComponent<NavMeshAgent>();

Now, in FlyPickup.cs:

Add this to the if statement just above Destroy(gameObject);

BirdMovement.speedIncreaser.acceleration++;
BirdMovement.speedIncreaser.speed++;

This will very quickly greatly increase the speed of the bird chasing the player, probably too quickly, so it will involve some tweaking, but this is a very basic way to do it.