Prelab:
Download the code package for the lab here.
Recall the following diagram from the reading on fireflies:
Feeling stuck? Here is a further description of the algorithm by Marton:
-
Using the variables given, fill in the two blanks below with the options provided to complete the part of the code in the Charge() function for when the firefly should send the message to flash.
-
-
-
- Your options are:
-
-
-
The following diagram describes the flow of the firefly program. Arrows represent calls from one function to another. Answer which of the following functions fits in each blank space.
-
-
- Your options are:
- (ignore the “IEnumerator” before each one. We will explain what that means during lab)
-
Lab:
Part 0: TA Demo of Coroutine
Part 1: Flashing behaviour
- Open the ‘Firefly Testing’ scene
- Open FireflyLights.cs
- All the code you will be writing today will be in this file
- Complete the TODOs for the following functions. Take a look at the SendMessageToFlash function to get an idea of what these functions should look like. Note that we won’t be completing the sawFlash function until part 2.
- Charge function
- WaitToCharge function
- Test your firefly
- At this point, your firefly should be flashing at a steady 1 second rhythm (might be slower on laptop). Make sure this is working before moving on to part 2.
Part 2: Synchronizing behaviour
- Implement the code for SenseFlashes function
- Test that SenseFlashes is working by clicking your left mouse to simulate it seeing another flash
- For this part, it may be helpful to increase the delayMultiplier so things move a bit slower. You can find the slider for this in the inspector when you have the flock selected.
- Show your TA the functions you implemented in part 1 and 2.
Part 3: Flocking behaviour
- Open the ‘Firefly Flock’ scene
- Press play and take a moment at your pretty flashing behaviour which you implemented in parts 1 and 2.
- Observe the movements of the fireflies in the scene.
- Click on the flock object in the hierarchy.
- Look at the flock script variables in the inspector
- Experiment with changing the sliders around as the program is running. Think about what each slider is controlling. What changes about the movement when each slider is changed?
- Look for 2 or more distinct emergent behaviors and note the flocking behavior variable values for each one. Show one of the behaviors to your TA and tell your TA what you think each slider is controlling.
Postlab:
Remember to include your code as part of your submission
- Compare the firefly to the ants in this video. How are the behaviours of the ants similar to, and different from the fireflies? (100 words or less)
- How are the flashing and flocking algorithms both examples of emergent behaviour? What are the lower level rules and higher level emergent behaviour of each? (100 words or less)