{"id":547,"date":"2020-10-02T12:15:30","date_gmt":"2020-10-02T19:15:30","guid":{"rendered":"https:\/\/blogs.ubc.ca\/cogs300\/?page_id=547"},"modified":"2024-02-02T14:09:47","modified_gmt":"2024-02-02T21:09:47","slug":"lab-3-fireflies","status":"publish","type":"page","link":"https:\/\/blogs.ubc.ca\/cogs300\/lab-3-fireflies\/","title":{"rendered":"Unity &#8211; Lab 3: Fireflies"},"content":{"rendered":"<h1>Prelab:<\/h1>\n<p>Download the code package for the lab <a href=\"https:\/\/github.com\/COGS300\/lab3-fireflies\">here<\/a>.<\/p>\n<p>Recall the following diagram from the reading on fireflies:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-553 size-large\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram-1024x886.png\" alt=\"\" width=\"620\" height=\"536\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram-1024x886.png 1024w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram-300x260.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram-768x664.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram-620x536.png 620w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/FireflyDiagram.png 1113w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Feeling stuck? Here is a further description of the algorithm by Marton:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/SbOljcInabU\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<ol>\n<li>\n<h4>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 <b>when<\/b> the firefly should <i>send the message<\/i> to flash.<\/h4>\n<\/li>\n<\/ol>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-561\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/chargeComments.png\" alt=\"\" width=\"902\" height=\"57\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/chargeComments.png 902w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/chargeComments-300x19.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/chargeComments-768x49.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/chargeComments-620x39.png 620w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/li>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-549\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/ChargeCode.png\" alt=\"\" width=\"285\" height=\"184\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Your options are:<\/strong><\/li>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-551 size-full\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables.png\" alt=\"\" width=\"1028\" height=\"615\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables.png 1028w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables-300x179.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables-1024x613.png 1024w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables-768x459.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyVariables-620x371.png 620w\" sizes=\"auto, (max-width: 1028px) 100vw, 1028px\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<h4>The following diagram describes the flow of the firefly program. Arrows represent calls from one function to another.\u00a0 Answer which of the following functions fits in each blank space.<\/h4>\n<\/li>\n<\/ol>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-554\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyControlFlow.png\" alt=\"\" width=\"763\" height=\"355\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyControlFlow.png 763w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyControlFlow-300x140.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/fireflyControlFlow-620x288.png 620w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/li>\n<li><strong>Your options are:<\/strong><\/li>\n<li>(ignore the &#8220;IEnumerator&#8221; before each one. We will explain what that means during lab)<\/li>\n<li><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-557\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge.png\" alt=\"\" width=\"1067\" height=\"83\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge.png 1067w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge-300x23.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge-1024x80.png 1024w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge-768x60.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/WaitToCharge-620x48.png 620w\" sizes=\"auto, (max-width: 1067px) 100vw, 1067px\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-556\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash.png\" alt=\"\" width=\"1038\" height=\"86\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash.png 1038w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash-300x25.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash-1024x85.png 1024w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash-768x64.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/SendMessageToFlash-620x51.png 620w\" sizes=\"auto, (max-width: 1038px) 100vw, 1038px\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-555\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/Charge.png\" alt=\"\" width=\"918\" height=\"82\" srcset=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/Charge.png 918w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/Charge-300x27.png 300w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/Charge-768x69.png 768w, https:\/\/blogs.ubc.ca\/cogs300\/files\/2020\/10\/Charge-620x55.png 620w\" sizes=\"auto, (max-width: 918px) 100vw, 918px\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\"><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h1><\/h1>\n<h1>Lab:<\/h1>\n<h3>Part 0: TA Demo of Coroutine<\/h3>\n<h3>Part 1: Flashing behaviour<\/h3>\n<ol>\n<li>Open the &#8216;Firefly Testing&#8217; scene<\/li>\n<li>Open FireflyLights.cs\n<ul>\n<li>All the code you will be writing today will be in this file<\/li>\n<\/ul>\n<\/li>\n<li>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&#8217;t be completing the sawFlash function until part 2.\n<ol>\n<li>Charge function<\/li>\n<li>WaitToCharge function<\/li>\n<\/ol>\n<\/li>\n<li>Test your firefly\n<ul>\n<li>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.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Part 2: Synchronizing behaviour<\/h3>\n<ol>\n<li>Implement the code for SenseFlashes function<\/li>\n<li>Test that SenseFlashes is working by clicking your left mouse to simulate it seeing another flash\n<ul>\n<li>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.<\/li>\n<\/ul>\n<\/li>\n<li>Show your TA the functions you implemented in part 1 and 2.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>Part 3: Flocking behaviour<\/h3>\n<ol>\n<li>Open the &#8216;Firefly Flock&#8217; scene<\/li>\n<li>Press play and take a moment at your pretty flashing behaviour which you implemented in parts 1 and 2.<\/li>\n<li>Observe the movements of the fireflies in the scene.<\/li>\n<li>Click on the flock object in the hierarchy.\n<ol>\n<li><a href=\"https:\/\/blogs.ubc.ca\/cogs300\/lab-3-fireflies\/firefliy-flock-selection\/\" rel=\"attachment wp-att-1614\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1614 size-thumbnail\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2023\/02\/firefliy-flock-selection-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<li>Look at the flock script variables in the inspector\n<ol>\n<li><a href=\"https:\/\/blogs.ubc.ca\/cogs300\/lab-3-fireflies\/firefliy-flock-variables\/\" rel=\"attachment wp-att-1615\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1615 size-thumbnail\" src=\"https:\/\/blogs.ubc.ca\/cogs300\/files\/2023\/02\/firefliy-flock-variables-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<li>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?<\/li>\n<li>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.<\/li>\n<\/ol>\n<h1>Postlab:<\/h1>\n<p><strong>Remember to include your code as part of your submission<\/strong><\/p>\n<ol>\n<li>Compare the firefly to the <a href=\"https:\/\/www.youtube.com\/watch?v=16W7c0mb-rE\" target=\"_blank\" rel=\"noopener noreferrer\">ants in this video<\/a>. <span class=\"TextRun SCXP195276232 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"false\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP195276232 BCX0\">How are the\u00a0<\/span><\/span><span class=\"TextRun SCXP195276232 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"false\" data-contrast=\"none\"><span class=\"SpellingError SCXP195276232 BCX0\">behaviours<\/span><\/span><span class=\"TextRun SCXP195276232 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"false\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP195276232 BCX0\">\u00a0of the ants\u00a0<\/span><span class=\"AdvancedProofingIssue SCXP195276232 BCX0\">similar to<\/span><span class=\"NormalTextRun SCXP195276232 BCX0\">, and different from the\u00a0<\/span><\/span><span class=\"TextRun SCXP195276232 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"false\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP195276232 BCX0\">fireflies? (100 words or less)<\/span><\/span><\/li>\n<li><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP132716284 BCX0\">How are the flashing and flocking algorithms both examples of\u00a0<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP132716284 BCX0\">emergent\u00a0<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"SpellingError SCXP132716284 BCX0\">behaviour<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP132716284 BCX0\">? What are the\u00a0<\/span><span class=\"ContextualSpellingAndGrammarError SCXP132716284 BCX0\">lower level<\/span><span class=\"NormalTextRun SCXP132716284 BCX0\">\u00a0rules and\u00a0<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"ContextualSpellingAndGrammarError SCXP132716284 BCX0\">higher level<\/span><span class=\"NormalTextRun SCXP132716284 BCX0\">\u00a0emergent\u00a0<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"SpellingError SCXP132716284 BCX0\">behaviour<\/span><\/span><span class=\"TextRun SCXP132716284 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-usefontface=\"true\" data-contrast=\"none\"><span class=\"NormalTextRun SCXP132716284 BCX0\">\u00a0of each?<\/span><\/span><span class=\"EOP SCXP132716284 BCX0\">\u200b <\/span>(100 words or less)<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prelab: Download the code package for the lab here. Recall the following diagram from the reading on fireflies: &nbsp; 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() [&hellip;]<\/p>\n","protected":false},"author":58788,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-547","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/pages\/547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/users\/58788"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/comments?post=547"}],"version-history":[{"count":30,"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/pages\/547\/revisions"}],"predecessor-version":[{"id":1730,"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/pages\/547\/revisions\/1730"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/cogs300\/wp-json\/wp\/v2\/media?parent=547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}