<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Fidelum Games]]></provider_name><provider_url><![CDATA[https://fidelumgames.wordpress.com]]></provider_url><author_name><![CDATA[jejoll]]></author_name><author_url><![CDATA[https://fidelumgames.wordpress.com/author/jejoll/]]></author_url><title><![CDATA[Migrated Post 2: Menacing Cubes&nbsp;Metamorphosize]]></title><type><![CDATA[link]]></type><html><![CDATA[<p><em>Originally posted on <a href="https://www.gamedev.net/blogs/entry/2262663-menacing-cubes-metamorphosize/" target="_blank" rel="noopener">GameDev.net</a> on March 4, 2017</em></p>
<p>In my <a href="https://fidelumgames.wordpress.com/2017/08/15/migrated-post-1-all-over-the-place-nailing-things-down-finding-my-way-movement-and-pathfinding/">LAST POST</a>, I talked mostly about some of the pathfinding options that I came up with. One of these solutions involved relying on raycasting to determine a path to my player, which was a fun exercise and yielded some really entertaining gifs. However, I decided to scrap that system in favor of using Unity&#8217;s built-in pathfinding system via the NavMesh and NavMeshAgent components.</p>
<p>However, because my game uses grid-based movement, I wasn&#8217;t going to be able to use said system out of the box.</p>
<p>My first solution to making Unity&#8217;s pathfinding play nicely with my game was to have the NavMeshAgent generate a path, and then overwrite that path by normalizing each of its points to align with my grid (whose cells are 3x3x4).</p>
<p>This would have been fine, but I soon realized that would have had to account for inserting points along lengthy straight paths, as the NavMeshAgent only calculates the corners, or turning points, along the path.</p>
<p>I could have done this, but after a bit more thought, I realized this would require unnecessarily complex logic, and that I could accomplish the exact same end result with a simpler, but similar solution.</p>
<p>Basically, I just decided that, each time my enemies move, I would have the NavMeshAgent generate a new path. Then, instead of normalizing the entire path, I would just look at the first point in the path and normalize that. Why bother normalizing the whole path if I&#8217;m only ever going to be moving to the first point in the path anyway?</p>
<p>After I did this and added a bit of extra logic to account for the locations and movements of other enemies, I was able to successfully have relatively large mobs moving in ways that (more or less) seem to make sense.</p>
<p>Check out this video of some menacing cubes following my player around:</p>
<div class="ipsEmbeddedVideo">
<div><span class="embed-youtube" style="text-align:center; display: block;"><iframe class="youtube-player" width="640" height="360" src="https://www.youtube.com/embed/bYnUOyDWHj8?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation"></iframe></span></div>
</div>
<p>After I got all of that mostly working, I decided that, although the game is still in a super early state, I owed it to myself to add a bit of polish and replace my cubes with one of the assets I acquired.</p>
<p>Check out the difference a couple of textures, 2 models and some animation configuration can make:</p>
<div class="ipsEmbeddedVideo">
<div><span class="embed-youtube" style="text-align:center; display: block;"><iframe class="youtube-player" width="640" height="360" src="https://www.youtube.com/embed/O9ujFvsNkFY?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation"></iframe></span></div>
</div>
<p>So there&#8217;s a lot going on in this video, so let me explain.</p>
<p>Firstly, here&#8217;s a list of the key features that you can see in the video:</p>
<ol>
<li>Grid based player movement and turning (thanks to the awesome <a href="http://www.pixelplacement.com/itween/index.php">iTween</a> library for all of my grid movement and rotation animations)</li>
<li>Mouse Look with rotational snapping (this was actually kind of fun to do)</li>
<li>Dissolving enemies (I&#8217;m still experimenting with different effects as you can see. Let me know which one you like).</li>
</ol>
<p>Secondly, here&#8217;s an explanation of what you&#8217;re seeing in the video:</p>
<p>The game view is on the left. This is what the player sees.</p>
<p>On the right we have a bird&#8217;s eye view courtesy of Unity&#8217;s Scene View.</p>
<p>Note that the game uses a true turn-based system. Enemies won&#8217;t perform an action until the player does. In the video it appears that the enemies sometimes take multiple turns, but I&#8217;m actually skipping my turn via keypresses in those cases. I guess I should also mention that if an enemy turns to face a new direction, it ends their turn, but the player can turn as many times as they want for free. I might change this in the future, depending on whether or not this becomes an &#8216;unfair&#8217; thing to be able to do and tilts the odds too much in the player&#8217;s favor.</p>
<p>The blue overlay you see is the walkable area of Unity&#8217;s NavMesh. You&#8217;ll notice that when an enemy enters an attack state, it will carve out the square that it occupies, making it non-walkable so that other enemies avoid that cell appropriately. I had to do it this way because, although Unity&#8217;s NavMeshAgents will avoid one another if they&#8217;re in control of movement, they don&#8217;t actually take into account other NavMeshAgents when they calculate the path, and since I&#8217;m manually moving my enemies, I needed a bit more customization.</p>
<p>You&#8217;ll also probably notice that some of the skeleton&#8217;s animations are a bit off&#8211;the attack in particular. Unfortunately, I couldn&#8217;t allow the animations to apply root motion as it interfered with my grid based movement, and as a result, some of the animations are a bit wonky. This was a purchased asset, which I&#8217;m still happy with, but if everything goes according to plan, hopefully I&#8217;ll be able to spend some money to have the animations updated to align with my grid.</p>
<p>Anyhow&#8211;that&#8217;s pretty much it for now.</p>
<p>I think my next focus will be on starting my inventory system. Looting, buying and selling are going to be a core gameplay component, so I&#8217;m going to have to get it right.</p>
]]></html></oembed>