
{"id":61,"date":"2021-01-28T08:28:11","date_gmt":"2021-01-28T08:28:11","guid":{"rendered":"http:\/\/crashedcreativity.pl\/?p=61"},"modified":"2022-06-22T20:02:59","modified_gmt":"2022-06-22T20:02:59","slug":"simplified-flock-algorithm-for-glow-worms-ai","status":"publish","type":"post","link":"https:\/\/crashedcreativity.pl\/index.php\/2021\/01\/28\/simplified-flock-algorithm-for-glow-worms-ai\/","title":{"rendered":"Simplified Flock Algorithm for glow worm&#8217;s AI"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"954\" height=\"339\" src=\"http:\/\/crashedcreativity.pl\/wp-content\/uploads\/2021\/01\/glow_woerms.jpg\" alt=\"\" class=\"wp-image-64\" srcset=\"https:\/\/crashedcreativity.pl\/wp-content\/uploads\/2021\/01\/glow_woerms.jpg 954w, https:\/\/crashedcreativity.pl\/wp-content\/uploads\/2021\/01\/glow_woerms-300x107.jpg 300w, https:\/\/crashedcreativity.pl\/wp-content\/uploads\/2021\/01\/glow_woerms-768x273.jpg 768w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/figure>\n\n\n\n<p>Hi! Today I want to show You how simply add something to make your scene more interesting. It is very simple AI algorithm  driving a light (I have used universar rendering pipie line to add 2d lights)<\/p>\n\n\n\n<p> I have used light because i wanted to experiment with this feature but it can be replaced with transparent texture. It will be more efficient,  lights consume lot of caluation power.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"http:\/\/crashedcreativity.pl\/wp-content\/uploads\/2021\/01\/srpol-platformer-scene04-Android-Unity-2019.3.5f1-Personal-PREVIEW-PACKAGES-IN-USE-_DX11_-2021-01-27-18-47-46.mp4\"><\/video><\/figure>\n\n\n\n<p>I have created C# component:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class GlowWorm : MonoBehaviour\n{\n    public Transform target;\n    public float speed = 1;\n    public float randomize = 1;\n    \/\/ Start is called before the first frame update\n    void Start()\n    {\n        \n    }\n\n    \/\/ Update is called once per frame\n    void Update()\n    {\n        float step = speed * Time.deltaTime; \/\/ Vector3.Distance(target.position, transform.position); ; \/\/ calculate distance to move\n        \n        transform.position = Vector3.MoveTowards(transform.position, target.position, step);\n        transform.position = new Vector3(transform.position.x+Random.Range(-randomize, randomize), transform.position.y + Random.Range(-randomize, randomize), transform.position.z);\n        \n    }\n}\n<\/code><\/pre>\n\n\n\n<p>As You can see this component will drive game object toward the target with &#8220;speed&#8221; velocity. Additionaly this movement will be disturbed with random fluctuation with &#8220;randomize&#8221; intensity<\/p>\n\n\n\n<p>You can place this component on light objects. Set target to &#8220;player&#8221; object. You can also chain lights that they can have differetnt target an will follow each other.<\/p>\n\n\n\n<p>This script can be extended. Eg When minimal distance threshold i exceeded then speed become negative if maximal distance threshold is exceeded then speed becomes postive again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi! Today I want to show You how simply add something to make your scene more interesting. It is very<\/p>\n<div class=\"read-button read_more_btn_text\"><a class=\"read_more\" href=\"https:\/\/crashedcreativity.pl\/index.php\/2021\/01\/28\/simplified-flock-algorithm-for-glow-worms-ai\/\">Read Now<span class=\"arrow_readm\"> &#x25BA;<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":64,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/posts\/61"}],"collection":[{"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":3,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions\/80"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/media\/64"}],"wp:attachment":[{"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crashedcreativity.pl\/index.php\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}