{"author_link":"\/users\/hdmmy","author_name":"hdmmy","author_uid":"hdmmy","comments":[],"epoch":1534427910,"event":"LD42","format":"md","ldjam_node_id":117151,"likes":8,"metadata":{"p_key":"120730","p_author":"hdmmy","p_authorkey":"1102275","p_urlkey":"336765","p_title":"How do I accomplish swarm thousands enemy without lag","p_cat":"LDJam ","p_event":"LD42","p_time":"1534427910","p_likes":"8","p_comments":"0","p_status":"WAYBACK","us_key":"1102275","us_name":"hdmmy","us_username":"hdmmy","event_start":"1533859200","event_key":"73","event_name":"LD 42"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD42","removed_author":false},"_superparent":97793,"_trust":1,"author":102275,"body":"I need 3 more comments to make my game have a rate!\n\nThis LudumDare game jam, I work alone and finish a shooting game [Zerg Coming!](https:\/\/ldjam.com\/events\/ludum-dare\/42\/zerg-coming).\n\nhttps:\/\/www.youtube.com\/watch?v=G_SsuKF0a9g\n\nThis is a preview of my game. The core mechanism is that you will fight with 7 round enemies, and you can shoot and dash.\n\nMany comments for my game is that \"you did a good pathfinding\", so here I want to share with others about the technology below the game. \n\n\nI use the Unity 2018.2.3f1, and in order to accomplish good pathfinding and group steering behavior, I use these methods below.\n\n### Group steering\n\nFirst of all, all the enemy has a dynamically simulated rigidbody2d, but there is no collision between enemy and enemy. There only have environment collision with the enemy. This relieves physic engine very much.\n\nI use two steering mode: seek steering and separate steering. If you don't familiar with steering, you can learn these steering modes at [The Nature of Code](https:\/\/natureofcode.com\/book\/chapter-6-autonomous-agents\/#chapter06_section4).\n\nWhen the enemy has a pathfinding route, it will follow the path use seek steering force. Applying steering force instead of simple change velocity direction will make the movement look smooth and natural.\n\n![image.png](\/\/\/raw\/38f\/81\/z\/1a00b.png)\n\nIf enemy only has seek steering, they will gradually overlap. To solve this problem, I come up with three solutions: \n\n1. Use [RVO](http:\/\/gamma.cs.unc.edu\/RVO2\/) make sure they will apart from each other\n2. Use physic engine and collider to force them apart from each other\n3. Use separate steering force to make they look apart from each other\n\nSince RVO and physic engine solution is bad for performance, I decided to use separate force solution.\n\nSeparate force work like this: when another unit is too close to you, you will receive a force to make yourself separate from it. [This website](https:\/\/natureofcode.com\/book\/chapter-6-autonomous-agents\/#chapter06_section4) explain this clearly.\n\n![image (1).png](\/\/\/raw\/38f\/81\/z\/1a00c.png)\n\nSo, each frame, an enemy will try to get the other near enemies information, and average each near enemy's position, to calculate a separate force.\n\nIn order to make finding near enemy information more efficient, I use the point octree to store each enemy position, I use the library [UnityOctree](https:\/\/github.com\/Nition\/UnityOctree). Since update octree is also a time-consume work, I write a simple logic that : If current enemies number is large than 1000, then each enemy every Random(0, 10) frame update its position in octree; if current enemies number is below 1000, then each enemy every Random(0, 5) frame update its position in octree.\n\n### Pathfinding -- Flow field\n\nNow let's get to the pathfinding. I use flow field to make the pathfinding. If you don't familiar with flow field, here is a simple and clearly article that explains flow field : [Basic Flow Fields]( https:\/\/howtorts.github.io\/2014\/01\/04\/basic-flow-fields.html). \n\nIn my achievement, I update the flow field every Random(0, 4) frame. If you understand how flow field work, you will note that update integration field is the most time-consume work. Luckily, there is a paper that uses jump point to efficient update integration field : [Faster Dijkstra Search on Uniform Cost Grids](http:\/\/www.gameaipro.com\/)(but you need to buy the GameAIPro3 first :) ).\n\nBelow is the flow field in my game, where the white lines are the flow field directions : \n\n![\u65e0\u6807\u9898.png](\/\/\/raw\/38f\/81\/z\/1a00d.png)\n---\n\nThat's all my accomplish. This is also my first time to join LudumDare, I am happy to join it :) !!","comments":4,"comments-timestamp":"2018-08-16T17:06:17Z","created":"2018-08-16T13:41:48Z","files":[],"files-timestamp":0,"id":117151,"love":8,"love-timestamp":"2018-08-16T17:05:05Z","meta":[],"modified":"2018-08-17T02:38:03Z","name":"How do I accomplish swarm thousands enemy without lag","node-timestamp":"2018-08-17T02:38:03Z","parent":102367,"parents":[1,5,9,97793,102367],"path":"\/events\/ludum-dare\/42\/zerg-coming\/how-do-i-accomplish-swarm-thousands-enemy-without-lag","published":"2018-08-16T13:58:30Z","scope":"public","slug":"how-do-i-accomplish-swarm-thousands-enemy-without-lag","subsubtype":"","subtype":"","type":"post","version":350161},"node_metadata":{"n_key":"117151","n_urlkey":"336765","n_parent":"102367","n_path":"\/events\/ludum-dare\/42\/zerg-coming\/how-do-i-accomplish-swarm-thousands-enemy-without-lag","n_slug":"how-do-i-accomplish-swarm-thousa","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"102275","n_created":"1534426908","n_modified":"1534473483","n_version":"350161","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/42\/zerg-coming\/how-do-i-accomplish-swarm-thousands-enemy-without-lag","text":"I need 3 more comments to make my game have a rate!\n\nThis LudumDare game jam, I work alone and finish a shooting game [Zerg Coming!](https:\/\/ldjam.com\/events\/ludum-dare\/42\/zerg-coming).\n\nhttps:\/\/www.youtube.com\/watch?v=G_SsuKF0a9g\n\nThis is a preview of my game. The core mechanism is that you will fight with 7 round enemies, and you can shoot and dash.\n\nMany comments for my game is that \"you did a good pathfinding\", so here I want to share with others about the technology below the game. \n\n\nI use the Unity 2018.2.3f1, and in order to accomplish good pathfinding and group steering behavior, I use these methods below.\n\n### Group steering\n\nFirst of all, all the enemy has a dynamically simulated rigidbody2d, but there is no collision between enemy and enemy. There only have environment collision with the enemy. This relieves physic engine very much.\n\nI use two steering mode: seek steering and separate steering. If you don't familiar with steering, you can learn these steering modes at [The Nature of Code](https:\/\/natureofcode.com\/book\/chapter-6-autonomous-agents\/#chapter06_section4).\n\nWhen the enemy has a pathfinding route, it will follow the path use seek steering force. Applying steering force instead of simple change velocity direction will make the movement look smooth and natural.\n\n![image.png](\/\/\/raw\/38f\/81\/z\/1a00b.png)\n\nIf enemy only has seek steering, they will gradually overlap. To solve this problem, I come up with three solutions: \n\n1. Use [RVO](http:\/\/gamma.cs.unc.edu\/RVO2\/) make sure they will apart from each other\n2. Use physic engine and collider to force them apart from each other\n3. Use separate steering force to make they look apart from each other\n\nSince RVO and physic engine solution is bad for performance, I decided to use separate force solution.\n\nSeparate force work like this: when another unit is too close to you, you will receive a force to make yourself separate from it. [This website](https:\/\/natureofcode.com\/book\/chapter-6-autonomous-agents\/#chapter06_section4) explain this clearly.\n\n![image (1).png](\/\/\/raw\/38f\/81\/z\/1a00c.png)\n\nSo, each frame, an enemy will try to get the other near enemies information, and average each near enemy's position, to calculate a separate force.\n\nIn order to make finding near enemy information more efficient, I use the point octree to store each enemy position, I use the library [UnityOctree](https:\/\/github.com\/Nition\/UnityOctree). Since update octree is also a time-consume work, I write a simple logic that : If current enemies number is large than 1000, then each enemy every Random(0, 10) frame update its position in octree; if current enemies number is below 1000, then each enemy every Random(0, 5) frame update its position in octree.\n\n### Pathfinding -- Flow field\n\nNow let's get to the pathfinding. I use flow field to make the pathfinding. If you don't familiar with flow field, here is a simple and clearly article that explains flow field : [Basic Flow Fields]( https:\/\/howtorts.github.io\/2014\/01\/04\/basic-flow-fields.html). \n\nIn my achievement, I update the flow field every Random(0, 4) frame. If you understand how flow field work, you will note that update integration field is the most time-consume work. Luckily, there is a paper that uses jump point to efficient update integration field : [Faster Dijkstra Search on Uniform Cost Grids](http:\/\/www.gameaipro.com\/)(but you need to buy the GameAIPro3 first :) ).\n\nBelow is the flow field in my game, where the white lines are the flow field directions : \n\n![\u65e0\u6807\u9898.png](\/\/\/raw\/38f\/81\/z\/1a00d.png)\n---\n\nThat's all my accomplish. This is also my first time to join LudumDare, I am happy to join it :) !!","title":"How do I accomplish swarm thousands enemy without lag","wayback_source":[]}