<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alessandro Valcepina on Medium]]></title>
        <description><![CDATA[Stories by Alessandro Valcepina on Medium]]></description>
        <link>https://medium.com/@alessandrovalcepina?source=rss-aa341345104b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*siBy5szjMUsGugKtC3XnEA.jpeg</url>
            <title>Stories by Alessandro Valcepina on Medium</title>
            <link>https://medium.com/@alessandrovalcepina?source=rss-aa341345104b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:26:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alessandrovalcepina/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a RTS-like minimap with Unity]]></title>
            <link>https://medium.com/@alessandrovalcepina/creating-a-rts-like-minimap-with-unity-9cd578dc4522?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cd578dc4522</guid>
            <category><![CDATA[rt]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[minimap]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Mon, 25 May 2020 10:52:29 GMT</pubDate>
            <atom:updated>2020-05-25T10:52:29.105Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A simple tutorial on creating a minimap for an RTS game</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/0*LtuYoRyATKMJFG0r" /></figure><p>RTS games often require the player to keep track of his and the enemy’s troops movement, while micromanaging resources gathering, base building and many other facets of their overall strategy.</p><p>To help cope with this demanding level of micromanagement the player has at his disposal several tools, like the ability of creating control groups, saving map locations and using a plethora of hotkeys. None of these tools, however, surpasses the unmatched usefulness of the minimap.</p><p>But how to reproduce the behaviour of a minimap in Unity?</p><p>Let’s find out together in this short tutorial.</p><p>Before we begin, just a few notes. <br>For this tutorial I used <strong>Unity 2019.3</strong> and a few free assets from the Asset Store. You can use any asset you like, but these are the ones you will need to reproduce exactly what you are seeing here:</p><ul><li><a href="https://assetstore.unity.com/packages/2d/gui/icons/sci-fi-interface-frames-10747">SciFi Interace Frames</a> contains everything you will need to create a good looking UI for your RTS.</li><li><a href="https://assetstore.unity.com/packages/2d/textures-materials/glass/stylized-grass-texture-153153">Stylized Terrain Textures</a> is a group of several assets that can be useful to quickly create a decently looking terrain.</li><li><a href="https://assetstore.unity.com/packages/3d/characters/robots/scifi-enemies-and-vehicles-15159">SciFi Enemies and Vehicles</a> while not strictly necessary for this tutorial, it is nice to have if you want to try and place some units on the map.</li></ul><p>Lastly, don’t forget that you can check the whole project at any time on <a href="https://github.com/avalcepina/simple-rts-unity">github</a>.</p><h3><strong>Scene setup</strong></h3><p>In order to have a meaningful map, you need to have some terrain. Let’s start by setting it up.</p><p>Creating a simple <strong>Terrain </strong>in Unity is trivial, however you should take care of adding some features and different textures, otherwise the minimap will look pretty dull and you will not be able to tell which part of it you are observing.<br>It would also make sense to place impassable mountains on the sides of the map so that it doesn’t end abruptly.</p><p>In my project I used scale 1 for the terrain, but any scale will work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*5EmMWeDmQbQlJ1yqYHlEzQ.png" /></figure><p>Once the terrain is in place it’s time to deal with the <strong>Camera</strong>.<br>Position the main camera wherever you like, but take care of setting its x rotation to 45 and its Projection to <strong>Orthographic</strong>.<br>If you need a quick reference, these are the settings I used in my project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*IEmBKgf1F1JDCRkWKJutIQ.png" /></figure><p>Now that the camera is in position, we want the player to control it, that is we want to be able to move it around, along the x and z axis, by using the directional keys. Let’s create a simple <strong>CameraController </strong>script that will achieve just that and assign it to the main camera.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e579549c9fd29f0e077762e116f44e1/href">https://medium.com/media/1e579549c9fd29f0e077762e116f44e1/href</a></iframe><p>As you can see this script also sets boundaries for the camera movement. You can find out the correct values for your project by moving the camera around, but, if you are using the same setting as shown before for the terrain, the following values should work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*g89cMYviBd8SZQsI8q6lTg.png" /></figure><p>If you now hit play, you will be able to test the main camera behaviour.</p><h3><strong>Creating the UI frame</strong></h3><p>The next step, before getting to the minimap creation, is to setup the context in which the minimap will reside, that is the <strong>UI</strong>.</p><p>We are going to create the shell of a UI similar to that of Starcraft, which you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*yRvLnW1Z1Dtr_nUx.png" /></figure><p>Mind the fact that the setup I used in my project largely depends upon the specific assets that have been used. So, although the general idea will probably be the same, you might have to make some changes if you are using different assets.</p><p>Start by creating a new <strong>Canvas</strong>, then create a <strong>Panel</strong>,named <strong>Bottom Panel</strong>, as its only child and set its height to 180 (or the value you feel looks better). Set position, pivot and anchor on this Panel to bottom and stretched horizontally, then set the Ui Scale Mode to Stretch With Screen Size.</p><p>Now create a child <strong>Raw Image</strong> for the Panel, name it <strong>Bottom Frame </strong>and assign to it the texture you intend to use to create the outer frame of the UI. If you are using the <a href="https://assetstore.unity.com/packages/2d/gui/icons/sci-fi-interface-frames-10747">Sci-fi Interface Frame</a> asset, then the texture will be <strong>CGY_4K_UltraHD_Interface_3_Frame_Glow.png</strong>. Set the height of the image to 180 and, again, set position, pivot and anchor for this image to bottom and stretched horizontally, so that it fills the panel completely.</p><p>Now you need to add the frame that will contain the minimap. For that you should create another <strong>Raw Image</strong>, named <strong>Minimap Frame</strong>, with texture <strong>CGY_4K_UltraHD_Interface_1A_Glow_1.png</strong>. Just like the Bottom Frame, this new image should be a child of Bottom Panel.</p><p>Set the image’s pivot, anchor and position to bottom left and stretched vertically and set its width to 170.</p><p>It’s now time to add the minimap. Since we didn’t set up anything yet, add an empty <strong>Raw Image </strong>as a child to<strong> Minimap Frame</strong>. Set anchor, pivot and position to center and resize both width and height to 160.</p><p>At the end of all this, you should have the following hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*tcwy3fuGksupOzerNvaAFg.png" /></figure><p>And your UI should look like this. The white square is obviously the Minimap placeholder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*SVe7zmGm8uGXe-GOJk88CQ.png" /></figure><p>Try to start the game to make sure the aspect ratio of all the elements is maintained.</p><p>You are now ready to proceed with the creation of the Minimap.</p><h3><strong>Creating the minimap</strong></h3><p>The concept behind the minimap is very simple. You need to create a second, top down, <strong>Camera</strong>, that looks at the terrain.</p><p>Let’s start with doing that.</p><p>Create a camera and name it <strong>Minimap Camera</strong>. Remove the Audio Listener from it, so that you don’t get an error from having two in the scene. Now create a new <strong>Render Texture</strong>; we are going to use it to display the Minimap Camera.<br>Now you should copy the following settings for your newly created camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_k50wmJI3ULdVLqESXhAeA.png" /></figure><p>Keep in mind that, if you used different values in the previous steps, you might have to adjust these settings.</p><p>Once you are happy with what the minimap camera is showing, go back to the Canvas you previously created and, more specifically, to Minimap Raw Image and set its texture to the Minimap Texture.</p><p>The end result should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*XPZhmOaLgce2oC1A-_LiYA.png" /></figure><p>Are we done, yet?</p><p>Not really. Having a minimap is nice and all, but if you cannot tell where the main camera is looking at, it’s not really that useful.</p><p>To fix this problem we want to draw, on the minimap camera, a small square that matches the main camera position and field of view.</p><p>The easiest way to do that is through a script, which we will call <strong>MinimapController</strong>.</p><p>Here’s the code for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1097bb0e01ec5c7a3f896cfcc4b89a3/href">https://medium.com/media/d1097bb0e01ec5c7a3f896cfcc4b89a3/href</a></iframe><p>To put it simply, the script is <strong>Raycasting </strong>at the corners of the main camera view and then mapping the world points identified this way to the minimap viewport. This gives us the max values for x and y to be used to draw the square on the minimap.</p><p>We are handling the drawing with <strong>GL</strong>, by creating four quads with the specified width and setting the color to red.<br>Once the script has been added to the Minimap Camera, we need to fill all its fields.</p><p>For the <strong>cameraBoxMaterial </strong>field, just create a material and change its shader to the Sprites/Default shader, or any another vertex shader, in order to be able to set the color through GL.Color.<br>For the <strong>minimap</strong>, just assign the Minimap Camera.<br>For the <strong>lineWidth </strong>you can experiment a bit and see what you like, but, personally, I settled for 0.012.<br>Finally, for the <strong>mapCollider </strong>field you might be tempted to use the terrain collider, but, due to the irregularities of the terrain, that can cause problems.</p><p>Instead you can create a GameObject called <strong>TerrainWrapper </strong>and move the terrain inside it. Now add to the TerrainWrapper a new box collider component and set its fields as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*axvU_Vq5J6AdsylOOLL5HQ.png" /></figure><p>You can now use this collider instead of the terrain’s one.</p><p>If you did everything we discussed, by hitting play you should see something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pgw1dQq75GAppJBDIju-_w.png" /></figure><p>When you move the camera around the red box should move as well.</p><h3><strong>What about units?</strong></h3><p>At this point you might wonder how to show the player and enemy units on the minimap as colored dots.</p><p>That’s actually quite easy to achieve.<br>Place you unit somewhere on the terrain, create a wrapping <strong>GameObject </strong>and, together with the unit, add a <strong>Sphere </strong>to it as a child. Resize and reposition the sphere so that it overlaps with the unit and so that it can be seen in the minimap. Now create a <strong>Material </strong>with the color you want your unit to show up in the minimap and assign it to the sphere.</p><p>Now it’s only a matter of making the sphere invisible in the main camera and the unit invisible in the minimap.</p><p>Create two <strong>Layers </strong>called respectively <strong>Minimap</strong> and <strong>Unit</strong>. Select the main camera and uncheck the Minimap layer from the <strong>Cullin Mask</strong> settings, then select the Minimap Camera and do the same thing for the Unit layer.</p><p>Voila! The unit now shows up as a dot in the minimap and as a unit in the main view.</p><h3><strong>Conclusions:</strong></h3><p>I hope you enjoyed this tutorial and that you found it useful. <br>There are still some improvements that you could make to this minimap implementation. For example adding flashing alerts when your units are in danger, adding different filters to highlight different features of the terrain and, most importantly, allowing to set the camera position based on a click in the minimap. Now that you have the overall setup ready, these should be rather easy to accomplish.<br>For the time being I wish you good luck and I hope to see you soon in the next tutorial!</p><p>If you want to learn more about Unity don’t forget to check out my <a href="https://medium.com/@alessandrovalcepina">previous posts</a> and, if you are interested in knowing more about me feel free to follow me on <a href="https://github.com/avalcepina">github </a>and <a href="https://www.linkedin.com/in/alessandro-valcepina-6793b910/">linkedin</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cd578dc4522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recreating Asteroids with Unity — Part 2]]></title>
            <link>https://medium.com/@alessandrovalcepina/recreating-asteroids-with-unity-part-2-c1c5dc67965d?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1c5dc67965d</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Wed, 22 Apr 2020 10:56:59 GMT</pubDate>
            <atom:updated>2020-04-22T10:56:59.472Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recreating Asteroids with Unity — Part 2</h3><p><strong>A simple tutorial on re-creating the classic Asteroids with Unity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/0*HQa_IEQCMN7aG6aL.jpg" /></figure><p>Welcome back to the last part of this seris on re-creating the classic Asteroids game with Unity 3D 2019. As usual, before we start, just a quick reminder that you can always check the source code for this project on <a href="https://github.com/avalcepina/asteroids-unity">github</a>.</p><p>Now if you are ready to go, let’s get started!</p><h3><strong>Setting goals</strong></h3><p>In the <a href="https://medium.com/@alessandrovalcepina/recreating-asteroids-with-unity-part-1-a596fb28efdb">first part</a> of the tutorial we set up the basic gameplay. We took care of periodically spawning asteroids and positioning the starship and we also allowed the player to control the ship and shoot.<br>Now need to check for collisions and take care of destroying both the asteroids and the player ship, when necessary. <br>Finally we want to add some nice UI and a background.</p><h3><strong>Collisions and death</strong></h3><p>If we want to allow our asteroids and ship to explode, we first need a way to track their health.<br>For this purpose, let’s add to both prefabs a new script called <strong>HealthController</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ad3bf6ab1eac9194ac4488394f06a6a/href">https://medium.com/media/5ad3bf6ab1eac9194ac4488394f06a6a/href</a></iframe><p>The script exposes a method DealDamage that decreases the currentHealth value based on the damage parameter. It also takes care of spawning an explosion prefab and destroying both this prefab and the parent game object after a short interval.<br>Obviously for this to work we need to provide an explosion. We will again resort to the Asset Store to find one. In my project I used the free <a href="https://assetstore.unity.com/packages/essentials/tutorial-projects/unity-particle-pack-127325">Unity Particle Pack</a>, but if you have any other preference just go for it. <br>In case you decide to use the suggested asset, then keep in mind importing just the FireExplosionEffects and the Shared folders should be enough for our needs.<br>Once the asset is imported simply drag the explosion prefab (SmallExplosionEffect) to the explosion field on both the asteroid and starship prefab.</p><p>Now we need something to call the DealDamage method at the appropriate time. <br>Let’s edit the <strong>AsteroidController </strong>script we created in part one of the tutorial by adding the following fields and method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7eeaa8124c9ceb8e369a4ca029383a1f/href">https://medium.com/media/7eeaa8124c9ceb8e369a4ca029383a1f/href</a></iframe><p>The script allows an asteroid to deal damage upon contact to the player. If the ship stays in contact with the asteroid it will keep on taking damage at regular intervals. Take note of the fact that the script is identifying the player based on its tag, so make sure to modify the ship prefab by adding the appropriate “Player” tag.<br>Lastly, don’t forget to assign a value to the Damage field. 20 seems like a sensible amount of damage.</p><p>We now have a way for asteroids to destroy the ship, but we have no way for the ship to destroy the asteroids.</p><p>To achieve that, we only need to add the following to the <strong>LaserBehaviour </strong>script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ad8d93ffa312f77f5c452794c139b68/href">https://medium.com/media/0ad8d93ffa312f77f5c452794c139b68/href</a></iframe><p>If you hit play, you should be able to fly around destroying asteroids with your laser and it should also be possible for you to explode if you crash into asteroids too much.</p><h3><strong>User Interface</strong></h3><p>Having implemented basically all fundamental gameplay aspects, this makes for a good time to focus on the UI, which is, currently, sorely lacking.</p><p>In the <a href="https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-1-a53e8204c86">previous tutorial on Pong</a>, we kept all the interface in different planes but in the same scene. This time, however, we will do things a bit differently.<br>We want to have a main menu from which the player will be able to start and quit the game, but we will implement it in a separate scene.</p><p>So let’s first rename the current scene to <strong>GameScene </strong>and then let’s create a new one called <strong>MainMenuScene</strong>.</p><p>In the newly created scene we should add a canvas containing aplane with a <strong>StartGameButton </strong>and an <strong>EndGameButton </strong>with text “New Game” and “Quit” respectively. Take care of anchoring the two buttons to the center and position them one above the other.</p><p>Now we need to add some logic for our UI.</p><p>Create a new empty game object named <strong>MainMenuController </strong>and add a script with the same name to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a6e4f493fb127ac73a0fbad01674887/href">https://medium.com/media/6a6e4f493fb127ac73a0fbad01674887/href</a></iframe><p>You should be able to tell at a glance that this script does way more than simply implementing the logic for those two buttons. In fact the script will also send asteroids flying across the screen form the right to the left, creating a nice background for the menu.</p><p>Feel free to set the values you deem more appropriate to the various fields and don’t forget to add the asteroid prefab to it.</p><p>Now go back to the buttons and bind the On Click for StartGameButton to StartGame and the EndGameButton to QuitGame in MainMenuController.</p><p>The last thing you need to do is positioning your main camera correctly. In my case a z value of -30 worked the best.</p><p>Now save your scene and add both scenes to the build in Build Settings, so that you will be able to load the GameScene when hitting the StartGameButton.</p><h3><strong>Scoring and death</strong></h3><p>Our game already has a sound gameplay, but it lacks purpose. The quickest way in which we can provide the player with a goal is by implementing some kind of scoring mechanism.<br>The plan is simple. Every asteroid will be worth some points and, when an asteroid is destroyed, we will increase the player score by that amount. At the same time we will take care of implementing a game over state.</p><p>Open the GameScene and add a new canvas to it, then create two panels named <strong>GamePanel </strong>and <strong>GameOverPanel</strong>.</p><p>Let’s focus first on the GamePanel. <br>Create two text elements inside the panel. Name the first one ScoreLabel and set its value to “Score:”. Name the second one ScoreValue and set its value to “0”. Now anchor them both to the top right and position them next to each other, resizing them as you see fit to make them look nice.</p><p>Switch over to the GameOverPanel and simply place a red colored “Game Over” text anchored in the middle.</p><p>Now onto the logic. We are going to edit the <strong>GameController </strong>script by adding the following fields.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c75ff5938cb88b18655b9420b55a48d/href">https://medium.com/media/3c75ff5938cb88b18655b9420b55a48d/href</a></iframe><p>Set gamePanel and gameOverPanel to the two panels you just created and scoreValue to the text with the same name.</p><p>At the beginning of the Start method add the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5602624c65c9cd6b3b712bf44809d33e/href">https://medium.com/media/5602624c65c9cd6b3b712bf44809d33e/href</a></iframe><p>This will take care of enabling the game panel and hiding the game over panel.</p><p>Now let’s add a method to increase the player score.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc0e21d2f656e311173842987411eb66/href">https://medium.com/media/fc0e21d2f656e311173842987411eb66/href</a></iframe><p>And another method to show the game over screen when the player dies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/883ac8aa7e09d27870ba0e4d953ebeb8/href">https://medium.com/media/883ac8aa7e09d27870ba0e4d953ebeb8/href</a></iframe><p>Let’s also change the Update method so that it checks that the player is alive. This will prevent some errors when the player is dead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a72c760dda3061f2faefb92b74bf61b5/href">https://medium.com/media/a72c760dda3061f2faefb92b74bf61b5/href</a></iframe><p>Those were a lot of changes! However we are not done yet.<br>We need to invoke the PlayerDies method from somewhere and that somewhere will be the <strong>PlayerController </strong>script. So let’s edit it by adding the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ebe75a2f7efa45854b248d8e210c5d1/href">https://medium.com/media/5ebe75a2f7efa45854b248d8e210c5d1/href</a></iframe><p>This will make it so that when the player dies the game ends as expected.</p><p>Almost done.<br>Open the <strong>HealthController </strong>script and, as shown below, add the scoreValue field, change the DealDamage method so that it increases the score upon death and the start method so that it retrieves a reference to GameController.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c620d29338a88d673a5f313ffe1f650/href">https://medium.com/media/6c620d29338a88d673a5f313ffe1f650/href</a></iframe><p>This should be all.<br>If you try starting the game now you will see the score increase every time you destroy an asteroid and, should you die, you will get a “nice” game over screen.</p><h3><strong>Finishing touches</strong></h3><p>The game is almost complete. There’s not much left to do. <br>The most obvious feature we are missing is a nice, starry background. This will be easily taken care of by, once again, accessing the Asset Store and importing the appropriate asset. Any skybox will do, but my preference goes to <a href="https://assetstore.unity.com/packages/2d/textures-materials/dynamic-space-background-lite-104606?aid=1100l355n&amp;gclid=CjwKCAjw7e_0BRB7EiwAlH-goH5Dnw9oXCTi8iizO_YKH-0MoR1d8IHxrPjT4L27YaX89RKLFh_3vxoCKgMQAvD_BwE&amp;pubref=UnityAssets%2ADyn03%2A1723478829%2A67594162255%2A336302044055%2Ag%2A%2A%2Ab%2Ac%2Agclid%3DCjwKCAjw7e_0BRB7EiwAlH-goH5Dnw9oXCTi8iizO_YKH-0MoR1d8IHxrPjT4L27YaX89RKLFh_3vxoCKgMQAvD_BwE&amp;utm_source=aff">Dynamic Space Background Lite</a>. <br>Once imported create a new material called Skybox and, as a Shader, select Skybox/6 sided, then set Front value to the sprite of your choice from the selection offered by the asset.</p><p>Now select the main camera and add a Skybox component with the value set to the newly create material.<br>Make sure your camera x value is set to -30 and the field of view is 45 and voilà, you got yourself a pretty nice background and also you also managed to complete the project!</p><p>Enjoy a video of the final product!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYVSqqJa_Hiw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYVSqqJa_Hiw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYVSqqJa_Hiw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/870aefb598ed364a7d00349f14526766/href">https://medium.com/media/870aefb598ed364a7d00349f14526766/href</a></iframe><h3><strong>What’s next?</strong></h3><p>As for the previous tutorial, also this one has brought you only so far. There’s still much you can do to improve this prototype and make it into a real game. Before letting you go I just wanted to provide you with some ideas:</p><ul><li><strong>High score screen</strong>: since at the moment the only goal is to get more points it would make sense to have a high score screen and allow the player to input his name when he loses.</li><li><strong>Different asteroids</strong>: it would be nice to have more than one type of asteroid. You could make more resilient asteroids, bigger asteroids, homing asteroids, asteroids that split upon exploding, fire asteroids, indestructible asteroids and so on. The possibilities are endless.</li><li><strong>Levels</strong>: currently the game is always the same and makes for a repetitive experience. You could improve that by introducing levels. Each level should contain one or more waves of asteroids and the start of a new level should be signaled by a text at the center of the screen displaying the level number.</li><li><strong>Powerups</strong>: different asteroids and levels will definitely increase the difficulty of the game. To compensate for that you could introduce power-ups that drop from destroyed asteroids or that are rarely spawned and move across the screen tempting the player to catch them. Power-ups could grant literally anything: shields, different modes of fire, extra health, pods and more.</li><li><strong>Multiplayer</strong>: it is always nice to play a good old arcade game with a friend, either online or locally.</li></ul><p><strong>Goodbye, for now!</strong></p><p>This concludes the second tutorial in this series. I hope you enjoyed it and, if you did, please leave a clap. <br>Also, if you didn’t do it yet, you should take a look at the <a href="https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-1-a53e8204c86">first tutorial</a>, which will show you how to recreate another classi: Pong!</p><p>Good luck with your projects and see you soon with another tutorial!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1c5dc67965d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recreating Asteroids with Unity — Part 1]]></title>
            <link>https://medium.com/@alessandrovalcepina/recreating-asteroids-with-unity-part-1-a596fb28efdb?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a596fb28efdb</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[arcade]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 20:30:14 GMT</pubDate>
            <atom:updated>2020-04-13T21:27:40.718Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recreating Asteroids with Unity — Part 1</h3><p><strong>A simple tutorial on re-creating the classic Asteroids with Unity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/0*9u4mla8LfQYZ0mUE" /></figure><p>Welcome back fellow aspiring Unity developers!<br>If you enjoyed my previous post, get ready for more, because we are going to re-create another old times classic! <br>If, on the other hand, you don’t know what I am talking about, be aware that you can find the previous tutorial in this series <a href="https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-1-a53e8204c86">here</a>.</p><p>Now, before we start, I want to remind you that this project has been developed using Unity 2019 and that you can always check the full source code on <a href="https://github.com/avalcepina/asteroids-unity">github</a>. Mind the fact that, this time, the git repository does not include the assets, which are anyway freely available from the assets store and can be easily replace with different ones.</p><h3><strong>Asteroids</strong></h3><p>Let’s start by refreshing our memory. What is <strong>Asteroids</strong>?<br>Asteroids is a very famous arcade game, developed in 1979, in which the player takes control of a spaceship and has to shoot down lots of asteroids that are travelling across the screen, trying at the same time to avoid any collision. <br>You can see the original gameplay in the video below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWYSupJ5r2zo%3Fstart%3D212%26feature%3Doembed%26start%3D212&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWYSupJ5r2zo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWYSupJ5r2zo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a780cc97fdae35f92471d7694855fec/href">https://medium.com/media/8a780cc97fdae35f92471d7694855fec/href</a></iframe><h3><strong>Designing the game</strong></h3><p>The plan is simple. We want a gameplay similar to the original one: our ship should be able to turn around and move freely and, at the same time, shoot asteroids that come randomly from the sides. Also leaving the field of view should move the ship to the opposite side of the screen. <br>Asteroids that are being hit should explode after a few hits and the ship itself should explode when hit by an asteroid.</p><p>As far as the UI goes we want to have at the very least a starting menu with some dynamic background and a game over screen. Also, while playing, we want to see the player score.</p><p>That’s it. Now that the goal is set and clear, we are ready to start!</p><h3><strong>The starship</strong></h3><p>We are going to start from our starship. You can use any model you like, but, for this tutorial, you can simply rely on any free asset from the assets store. In my project I have used <a href="https://assetstore.unity.com/packages/3d/vehicles/space/uav-trident-46128">UAV Trident</a>.</p><p>Import the asset you’ve chosen and drag the ship prefab in the scene, taking care to reset its position. Now open the the UAV Trident ship select the default object and change its rotation to 0, 180,0, so that it is facing the correct direction. <br>Select again the Uav Trident game object and set the x axis rotation to -90. This is a temporary setting to allow you to test the ship at the end of this section. We won’t need it in the long run.</p><p>Now add the following <strong>PlayerController </strong>script to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/180f9e0e3c48f8351da1a8524c4b8420/href">https://medium.com/media/180f9e0e3c48f8351da1a8524c4b8420/href</a></iframe><p>At the top of the script we have a few fields for which we should provide values. In particular take note of the fact that you will need a laser prefab. For now simply create a small enough capsule with a red colored material and assign it to the field. As a quick reference, these are the values I used in my prototype.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*k9rTZe-JPsTs0EC4809LmA.png" /></figure><p>Save the laser game object as a prefab and delete it before assigning it as a value for the script.</p><p>On the starship you can set <strong>Rotation Speed </strong>to 90 and <strong>Movement Speed</strong> to 150, but feel free to play around with the values to find the ones you prefer. The <strong>Cooldown </strong>field represents the pace at which lasers are being shot from the ship. In myproject I set it to 0.3.<br>As you can see in the <strong>Update </strong>method, we are allowing the player to control the ship via WASD keys and to shoot the laser by pressing the spacebar.<br>Now add a rigidbody to the ship and set its value like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*HitLS9ZlhOAvQp7sQEdHEg.png" /></figure><p>In particular a 0.5 Drag will give the ship that “drifting behaviour” when you stop pressing a movement key.</p><p>We will also need two Capsule Colliders (or one capsule cinematic collider and a mesh collider if you prefer) with the following settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*qemf7wnl9AsqUXTzKyM5LA.png" /></figure><p>We will use the non cinematic collider for proper collision detection and the cinematic one to find the player more reliably (more on that later).</p><p>Obviously, once created by the PlayerController script, the laser is not gonna do anything on its own. Hence, we will need to add a <strong>LaserBehaviour </strong>script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb393e4b4fd58286f2815d800d98ab2/href">https://medium.com/media/afb393e4b4fd58286f2815d800d98ab2/href</a></iframe><p>As you can see, the LaserBehaviour script, among other things, also contains the method OnBecameInvisible to destroy the laser when it exits the screen. <br>Don’t forget to set the Speed field value in the inspector. A value of 40 should do.</p><p>Now set the <strong>Main Camera</strong> to this position, so that it looks in the right direction, and you will be ready to test your ship’s movement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*e8jnGG5yGrFDAqBAaUv9MA.png" /></figure><h3><strong>The first asteroid</strong></h3><p>It’s now time to take care of the antagonist to our starship: the asteroids.<br>Once more, let’s a take a look at the Assets store and see what it has to offer in the way of asteroids. There are several free options, but, personally, I decided to go with this free <a href="https://assetstore.unity.com/packages/3d/environments/asteroids-pack-84988">Asteroid Pack</a>.</p><p>Import the asset and drag the prefab of your choice into the scene. <br>Take note of the fact that the prefab comes with a script controlling the random rotation of the asteroid and with a rigidbody.<br>In the latter, set the mass to 1 and the drag to 0, so that we will have a easier time moving the asteroid around. Also freeze movement on the z axis.</p><p>After all is done, your rigidbody should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*r5A5aY_KHWIBER3NOQVMZQ.png" /></figure><p>Add a new script to the asteroid and call it <strong>AsteroidController</strong>. For the time being it will be very simple and it will look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b748e7da073910cc144ab08dbe79a20/href">https://medium.com/media/0b748e7da073910cc144ab08dbe79a20/href</a></iframe><p>The script simply adds a force to move the asteroid forward and implements the method OnBecameInvisible to destroy the asteroid once it leaves the viewing field.</p><p>Don’t forget to add a capsule collider to you game object, so that collisions with the ship and other asteroids will be handled.</p><p>Now add a 45 degrees rotation on the y axis to the asteroid and you should be able to see it moving by hitting play.</p><h3><strong>The Game Controller</strong></h3><p>As the last step for this first post, we need to add some sort of “glue” that will hold together all the pieces we created so far. That will be our Game Controller. <br>Create an empty game object and add a new <strong>GameController </strong>script to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81ce196feb1a67558e2b34066b91ce1/href">https://medium.com/media/c81ce196feb1a67558e2b34066b91ce1/href</a></iframe><p>For the script to compile we will also need to add another file containing the struct we will use to find the correct position where to spawn the asteroids.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e4a662169c0f7e9271327bb694241dd/href">https://medium.com/media/4e4a662169c0f7e9271327bb694241dd/href</a></iframe><p>Let’s go through the logic we just implemented, because it’s quite complex and requires explanation. <br>In the <strong>Start </strong>method we are instantiating the player prefab (aka the starship) and setting the screen center and screen boundaries. These are used later on, specifically in the <strong>InstantiateRandomAsteroid </strong>method, to instantiate asteroids just outside the viewing field so that they don’t just blink into existence. Take also note of the fact that in this method we are relying on an OverlapBox to avoid spawning two asteroids on top of each other.<br>All asteroids created by this method are sent flying towards the center of the screen and, potentially, across it, unless they meet another asteroid or the player on their paths.</p><p>The other interesting part of the script is the <strong>FindPlayer </strong>method, which is responsible to check whether the Player is still visible or not. One might argue we could have used OnBecameInvisible, just as we did for the laser and the asteroid, however this method has the problem that it will also consider the editor scene camera to verify visibility and, on top of that, I had some odd behaviour with it, while testing, so I decided to go with a more reliable, albeit more complex, solution.</p><p>Both InstantiateRandomAsteroid and FindPlayer are called in the Monobehaviour <strong>Update </strong>method. In here we check if the player is visible with FindPlayer and, if it is not, we calculate its new position on the other side of the screen. Then, if the timer is up, we spawn a new asteroid in a random position outside the view.</p><p>Now that the script purpose is clearer, let’s reset the position of both the Starship and the Asteroid (particularly the rotation) and save them as prefabs, then delete them.<br>You can now assign the newly created prefabs as values for the appropriate fields in the controller.<br>You can then set the other values to your liking, but, as a reference, I’m going to provide the values I used in my project. Keep in mind the scale values, particularly, can vary based on the asteroid you used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*7LFEc-7Ng54TiLifi8ewKQ.png" /></figure><p>Now, if you start the game, you should see something like this.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5OSJG8B7BZI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5OSJG8B7BZI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5OSJG8B7BZI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/278a71253e88cc6844d657fef30e5f26/href">https://medium.com/media/278a71253e88cc6844d657fef30e5f26/href</a></iframe><p>Great! We got most of the mechanics we wanted to implement!</p><h3><strong>Coming up next</strong></h3><p>We reached our goal for this tutorial, but the game is far from over. We need to handle several mechanics like collisions, death and scoring and of course let’s not forget about the current complete lack of an UI. <br>In the next post we will tackle all these issues and some more, in the meantime I hope you enjoyed this post and a bid you farewell!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a596fb28efdb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recreating Pong with Unity -Part 2]]></title>
            <link>https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-2-ba3429d5a68f?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba3429d5a68f</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 11:08:55 GMT</pubDate>
            <atom:updated>2020-03-28T11:08:55.146Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A simple tutorial on re-creating a classic game with Unity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NEPnNopqmoAdOKTt.jpg" /></figure><p>Welcome to part 2 of these series of posts, in which we are trying to recreate Pong using Unity.<br>If you didn’t read part 1, I recommend that you do it before going forward. You can find it <a href="https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-1-a53e8204c86">here</a>. <br>Keep in mind this project has been developed using Unity 2019, so you might have to do things slightly differently if you are using a different version.<br>Also don’t forget you can always check the full code for the project here <a href="https://github.com/avalcepina/unity-pong">https://github.com/avalcepina/unity-pong</a>.</p><p>In the previous post, we set up the basic mechanics of Pong and, by the end, we had functioning game, which, however, lacked any kind of UI and victory conditions.<br>In this post we take care of that, starting with the former.</p><h3><strong>The plan</strong></h3><p>Let’s ask ourselves: what do we need to complete our game?<br>We want to set up a simple menu that allows us to start a new game or quit. We also want to implement a scoring system that tracks the number of times a player manages to have the ball slip past his opponent.<br>Finally we want a victory and defeat screen.<br>That’s our plan.</p><h3><strong>The UI</strong></h3><p>We will structure the UI in 4 different panels to which correspond 3 different game states. The UI panels will be:</p><ul><li><strong>The main menu</strong>: a simple menu with two options: “New Game” and “Quit Game”. We want the background of this menu to be the regular game but with two AI players, playing indefinitely. Basically demoing what the actual game will be like.</li><li><strong>The game panel</strong>: this is the panel the player sees after clicking on “New Game” on the main menu. Functionally it is the same as what was developed in the previous post but with two extra UI elements, i.e two score textes in the left and right upper corners.</li><li><strong>The game over screen and the victory screen</strong>: they are basically the same screen and they get displayed when we reach the game over state. They just display a victory or defeat text.</li></ul><p>Now that we defined what we want to do, let’s create a canvas and add four panels as its children. Let’s name them: “<strong>MainMenu</strong>”, “<strong>GameScreen</strong>”, “<strong>GameOverScreen</strong>”, “<strong>VictoryScreen</strong>”.</p><p>Under “MainMenu” create two buttons with one text each. Set the text field for the first one to “New Game” and the second to “Quit Game”.<br>Now position the two buttons in the center of the screen, one above the other.<br>The end result should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3ceRPkliTIosBrMzh11TQ.png" /></figure><p>Under “GameScreen” create 4 text elements and position two of them in the right upper corner and two of them in the left upper corner. Take care to set the anchor and pivot on both so that they respectively are in the upper right and upper left corner, this will make it easier for you to position them correctly. <br>Set one text in each group to the value “Score:” and the other one to “0”. <br>This is what you should have at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDp6vlYeBLw5_LPTp73wSA.png" /></figure><p>The last two panels simply require you to create a text in the center of the screen with a “Game Over” and “Victory!” message respectively.</p><h3><strong>Game states</strong></h3><p>In order for our UI to work properly we need to manage the different game states, based on which one of the four panels will be displayed, while the others will remain hidden. This is quite a complex task.<br>Let’s start by creating a game state enum as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7928296b8dddadc0a3f1c1cd84ed252f/href">https://medium.com/media/7928296b8dddadc0a3f1c1cd84ed252f/href</a></iframe><p>Now create an empty game object and add a new <strong>GameController </strong>script to it and copy the code below into it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3b26a926933b27f75251bf9b198dc3c/href">https://medium.com/media/c3b26a926933b27f75251bf9b198dc3c/href</a></iframe><p>Let’s look through the script and understand what the various methods are doing.</p><p>Right at the top, we have references to the player and ai paddle, the sphere prefabs and to the four UI panels we previously created. These are going to be used by the methods in the script.</p><p>The monobehaviour <strong>Start </strong>method is simply calling <strong>StartDemoGame</strong>, which, in turn, is setting the game state to DEMO, hiding all panels except for the Main Menu and finally calling <strong>ResetGame</strong>.</p><p>ResetGame is the method responsible for resetting the status of the ball and paddles when we change game state or (in the future) when a player scores.<br>If you look at how this is done you will notice that, before instantiating the prefabs, the script is looking for all the objects tagged as “Interactive” and destroying them. So take care to tag all your prefabs with the “Interactive” tag.</p><p>Now select your game controller game object and fill all fields in the inspector with the required prefabs and panels. <br>One last step before we are ready to test these changes. If you still have the sphere and the two paddles in your scene, delete them. As you’ve seen the script will take care of creating them as needed.</p><p>Now start your game and you should see something like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoC2Q-duE3bU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoC2Q-duE3bU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FoC2Q-duE3bU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/746f5bcbd7e0eeea0ff91e296648afc3/href">https://medium.com/media/746f5bcbd7e0eeea0ff91e296648afc3/href</a></iframe><p>Sadly if you try to click on New Game or Quit with your mouse, nothing will happen. That’s disappointing, but continue reading and we will fix it in a matter of minutes.</p><h3><strong>Starting the game</strong></h3><p>In order to be able to start and quit the game we need to add two methods to the GameController script. These are the <strong>StartNewGame</strong> and <strong>Quit </strong>methods shown in the following code snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bdd29569a60f0d5d60760fdafc6f00c/href">https://medium.com/media/9bdd29569a60f0d5d60760fdafc6f00c/href</a></iframe><p>Now select the New Game Button in the Main Menu panel and, in the button script component, add an on click handler and select the GameController and the StartNewGame method. Do the same for the Quit button and the Quit method and the buttons will finally be working.</p><h3><strong>Victory and Loss</strong></h3><p>We finally got to the last part of this tutorial, where we are going to implement the victory and loss conditions and tie up loose ends.<br>The first requirement is to be able to detect when a player scores a point and to keep track of a player total score.<br>This is quite simple.<br>Just add a new <strong>ScoreWall </strong>script to the left and right wall game objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb33b5dc8309d6e38a85757f6e5284ba/href">https://medium.com/media/bb33b5dc8309d6e38a85757f6e5284ba/href</a></iframe><p>Obviously this is not enough, since the GameController currently has no method called <strong>HandleScoring</strong>. Ideally this method should behave differently when the game state is PLAYING and when it is DEMO.<br>In the former case it should check which wall has been hit by the ball and increase either the player score or the enemy score. Also if the score reaches a configurable maximum, say 5, the game should end in victory or defeat.<br>In the second case we should just reset the game.<br>Below you can find the code for this method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ec1985b339bc18b2b4ac572dc405383/href">https://medium.com/media/4ec1985b339bc18b2b4ac572dc405383/href</a></iframe><p>You probably noticed that we also introduced references to the first and second player score textes and to the right and left walls. Take care of filling these fields with the correct game objects.<br>We also have calls to methods <strong>GameOver </strong>and <strong>Victory</strong>, which we need to implement. Their purpose is self explanatory and their implementation is quite similar, so let’s get them out of the way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91f81870dc566c6b36a5f7e287d47cbe/href">https://medium.com/media/91f81870dc566c6b36a5f7e287d47cbe/href</a></iframe><p>The two methods both set the gameState GAMEOVER, they destroy all objects tagged as “Interactive” and they display their respective panel. We could easily change this implementation to have a single panel and a single method to handle both scenarios, but we will not do it as part of this tutorial. Feel free to do it yourself if you’d like to experiment.</p><p>We are almost done!</p><p>Just one more thing. When the game ends we should be able to restart the game, but at the moment we end up stuck there. We can manage this by checking for key press on every update while the game state is in one of the two ending states. We should also put a timer to prevent the user from involuntarily skipping the final screen too quickly. In other words we should wait a couple seconds before allowing the player to go back to the main menu.</p><p>To do all of that let’s again modify the GameController script by implementing the monobehaviour Update as shown in the next snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46eb54ed90f27290c56318a6852b4aba/href">https://medium.com/media/46eb54ed90f27290c56318a6852b4aba/href</a></iframe><p>We are using the <strong>timeSinceGameOver </strong>field to track how long it has been since we got into the GAMEOVER state, so we should also reset it to zero in the Victory and GameOver methods.</p><p>Congratulations! You managed to get till the end of the tutorial and successfully brought back to life one of the great classic of the past!<br>The game you created should now look like this.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzmIOQAJymIs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzmIOQAJymIs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzmIOQAJymIs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0774267b7c8ade9c7a2e7ada9eb05c5/href">https://medium.com/media/b0774267b7c8ade9c7a2e7ada9eb05c5/href</a></iframe><h3><strong>Wrapping Up</strong></h3><p>This tutorial might be over, but the game can still be improved in several ways. You can try and experiment with it by adding new features. Here are some examples:</p><ul><li><strong>Multiplayer game mode</strong>. It would be great to be able to enjoy the game with another player. You could add an option for it in the main menu.</li><li><strong>Better graphics</strong>. For example you could add some effect when the ball hits the walls</li><li><strong>Power ups.</strong> For example ball multipliers, ball speed ups or slow downs.</li><li><strong>Game mods</strong>. These can be modifiers available from an options menu. You could change the ball maximum and minimum speed, the ball size, paddles speed and also overall difficulty of the game.</li><li><strong>Online multiplayer. </strong>After adding an option for multiplayer, the next step would be to allow player to play online.</li></ul><p>These are just a few ideas, the possibilities are basically endless and experimenting with any of them will greatly improve your knowledge.<br>I hope you enjoyed this tutorial and I look forward to see you again for the next one, which I will upload in the upcoming weeks! <br>In the meantime have fun playing and learning to create games with Unity!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba3429d5a68f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recreating Pong with Unity -Part 1]]></title>
            <link>https://medium.com/@alessandrovalcepina/recreating-pong-with-unity-part-1-a53e8204c86?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a53e8204c86</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 17:40:11 GMT</pubDate>
            <atom:updated>2020-03-19T17:40:11.467Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A simple tutorial on re-creating a classic game with Unity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2tYLPQhk6WX-Pk5K.jpg" /></figure><p>This is part 1 of a series of posts in which I will talk about recreating the classic game Pong with Unity. I undertook this project mainly to learn Unity’s basics and to start creating a portfolio of simple games. More games of the same kind will come in the future, so if you are interested stay tuned.</p><p>For now, however, let’s stay focused on the task at hand. The first thing we need to do is to set our goal. Let’s then take a look a the original game from 1972 , which you can see in the video below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfiShX2pTz9A&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfiShX2pTz9A&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FfiShX2pTz9A%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc2f5c4320b92ddc244fb25acca564bd/href">https://medium.com/media/fc2f5c4320b92ddc244fb25acca564bd/href</a></iframe><p>For our project we will just use this a basis and develop some things differently, but it’s good to keep the basic gameplay in mind.</p><p>Before we begin, don’t forget that, should you have any trouble or get lost, you can always check the full project on github at <a href="https://github.com/avalcepina/unity-pong">https://github.com/avalcepina/unity-pong</a>.</p><h3><strong>Setting up the playing field</strong></h3><p>Let’s get started by creating a new Unity 3D project. Although it would be possible to make this game in 2D, I decided to do it in 3D for learning purposes. Maybe in the future I can think about remaking it in 2D.</p><p>The first step will be defining the boundaries for our play field. We can do that by creating 4 walls, using quads. You can position the walls wherever you want, but the coordinates I used were 0, 0, 9 and 0, 0, -9, for the top and bottom walls, and 20, 0, 0 and -20, 0, 0 for the left and right walls. Let’s add a rigidbody to these walls and set each one to kinematic with continuous collision detection. This is necessary due to the speed the ball will be able to reach, which can sometimes allow it to pass through the walls if we don’t take this precaution.</p><p>Let’s now position the main camera so that it looks at our playing field. Personally I set it to 0, 40, 0 with a field of view equal to 35, but feel free to use different values if you like them better.</p><p>Your project should now look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqFTiMLAxeizs-hZCxPWOg.jpeg" /></figure><h3><strong>Creating the ball</strong></h3><p>It’s now time to work on our ball.</p><p>Before anything else we need to create a physic material that will help us control the bounciness of the ball. Let’s do that in a Materials folder. The new material should have the following values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*npZq5gPqq8-y5hrxQsvl7w.png" /></figure><p>This will strip away any friction from the material and make it bounce without losing any energy.</p><p>Now create a sphere and take care of resetting it so that it sits at the center of the screen. Add a rigidbody to it and, under constraints, freeze all rotations and the y position, then set the physic material you just created to the collider.</p><p>It’s time to define the behaviour of the sphere.</p><p>To do that, create a new Scripts folder and, inside it, a new c# script called SphereController that you can then add to your newly created sphere.</p><p>Open the SphereController script with your editor (I use visual studio code, but anything is fine) and replace the sample code with the following snippet to get the ball moving.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/351fbbc0cc2fd935dc09c48670401393/href">https://medium.com/media/351fbbc0cc2fd935dc09c48670401393/href</a></iframe><p>Set the thrust value on the script component to 600 and, when you hit play, you will see your ball moving and bouncing off walls.</p><p>Now create a Prefabs folder and save your ball as a new prefab. <br>We are doing this because, later on (in the next post), we want to be able to destroy and create balls as needed.</p><h3><strong>Creating the paddles</strong></h3><p>Now we need to create two paddles.</p><p>Let’s think about what exactly we need. <br>We need to be able to have one paddle be controlled by some sort of AI, while the other one will be player controlled. Also paddles will be parallel to the left and right walls and should only be able to move up and down.</p><p>Let’s create a cube and resize it so that it has the shape of a paddle. In my case I set the scale to 0.6, -0.2, 3.8. Let’s also add the physic material we previously created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*S-TVFgV5xO584vAfg51q7w.png" /></figure><p>Now add a rigidbody to it and</p><p>If you implemented the previous step you should have noticed that the way the ball bounces is a bit TOO realistic, meaning that if the ball hits a wall, or a pad, perpendicularly the reflection angle will be the same, causing the ball never to stray from the normal. <br>Now, that’s just not acceptable.</p><p>To deal with this issue, we could just have the ball start with a random angel, making it unlikely that it will get stuck, but where would the fun be in that?</p><p>We can instead solve this by applying the script below to the paddle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93aba734136b5fc54284a3ca597467f0/href">https://medium.com/media/93aba734136b5fc54284a3ca597467f0/href</a></iframe><p>This script will apply a new force to the ball when it hits the paddle, modifying the bounce direction slightly. The force will be directed upwards if the ball hits the paddle above the midpoint and downwards otherwise. This will also give some degree of control to the player or the AI.<br>As a side effect, that I think improves the gameplay, a player will be able to speed up or slow down the ball by correctly positioning the paddle.</p><p>If you hit play you should be able to verify this behaviour.<br>If everything is working correctly, let’s save the paddle to a prefab.</p><h3><strong>Paddle controllers</strong></h3><p>As we previously said, for our game, we need one player controlled and one ai controlled paddle.<br>So let’s create two prefab variants from our paddle prefab.</p><p>We will add the following script to the first, making it the player paddle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d973a69e2bce86dcd6fd628ad702eb0d/href">https://medium.com/media/d973a69e2bce86dcd6fd628ad702eb0d/href</a></iframe><p>And this other one to the second, making it the ai paddle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce694b44970a4ff999a36e219fa69621/href">https://medium.com/media/ce694b44970a4ff999a36e219fa69621/href</a></iframe><p>As you can probably tell, the first script is allowing the player to move the pad up and down with the directional arrows.</p><p>The second script, on the other hand, is a bit more complex. <br>The base rule in defining the AI behaviour is that we want to try and constantly match the ball z coordinate. It is probably not the most efficient way to assure that we will catch the ball, but it’s pretty effective nonetheless.<br>So effective, in fact, that we want to tune it down a bit in order for the player to have fun while playing.</p><p>We can achieve that by making three adjustments:</p><ul><li>We allow the paddle to match the ball position only when the ball is past the mid field.</li><li>When the paddle moves, it will move in the same direction for a minimum amount of time, causing it to be slightly imprecise in its movements.</li><li>When the ball is farther away than the mid field, the paddle will move randomly.</li></ul><p>Let’s now instantiate the two prefab variants in the scene and position the player paddle at 15, 0, 0 and the ai paddle at -15, 0, 0. Let’s also apply a rotation of 0, 180, 0 to both of them and set the sphere gameobject reference in the EnemyController Script.</p><p>When you hit play you should have something like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZBQt3IxFnIk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZBQt3IxFnIk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZBQt3IxFnIk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fafb9ed1f17a2e7e4363d2d3783593e5/href">https://medium.com/media/fafb9ed1f17a2e7e4363d2d3783593e5/href</a></iframe><p>We now have a very basic gameplay, in which the biggest problem is that there’s no victory condition, so the game will continue indefinitely.<br>That’s not good and we definitely need to take care of it, but this post is already becoming quite long, so let’s stop here for now.<br>We will continue setting up the game in the next post.</p><h3><strong>Coming up</strong></h3><p>In the next post we will conclude the implementation of our version of Pong by adding the following features:</p><ul><li>A starting menu, with a dynamic background showcasing the gameplay</li><li>Victor/loss conditions</li><li>Player score and lives</li><li>A game over screen</li></ul><p>For the time being I bid you farewell! I hope you enjoyed this short tutorial and I’m looking forward to see you again very soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a53e8204c86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom data sources for A/B testing with Vamp Lamia and Istio 1.0.2]]></title>
            <link>https://medium.com/@alessandrovalcepina/custom-data-sources-for-a-b-testing-with-vamp-lamia-and-istio-1-0-2-9a4c2e6985c4?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a4c2e6985c4</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[ab-testing]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Fri, 28 Sep 2018 14:01:59 GMT</pubDate>
            <atom:updated>2018-09-28T14:01:59.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*Byi8R0er7NW0axtm.png" /></figure><p>Welcome to our ongoing series of post on our experiences in using Istio during the development of Vamp Lamia.</p><p>In <a href="https://vamp.io/blog/welch-ttest-ab-testing-istio/">our previous post</a>, we presented Vamp Lamia’s approach to A/B testing and then delved deeper into how Experiments use Welch’s t-test to identify the test’s winner in a statistically sound way.</p><p>In both scenarios, however, we relied solely on Elasticsearch to gather the necessary statistics to calculate the A/B test outcome. This begs the question: what if we wanted to use a different source? In this post we will discuss the possibility of employing a custom data source, be it a different database or another application, deployed inside or outside the cluster.</p><h3>Custom Data Source</h3><p>Vamp Lamia has been developed with the clear goal of making it as modular as possible. For that reason its architecture is based on the usage of Drivers, that is components that can be easily replaced for each of the entities that Vamp Lamia is managing. In this specific case we want to replace the Driver responsible for gathering metrics from Elasticsearch with another one that can interface with a custom data source. That can be very easily done, provided the data source meets some requirements. Let’s see how that can be achieved.</p><p>First of all we have to figure out what to use as our source of data. For the sake of simplicity we will rely on a simple nodejs webservice that will return random values at each requests. Everything we require from this webservice is that it exposes a “/stats” endpoint that will respond to a request of the kind “/stats?subset=subset1” with the data pertaining to subset1 presented in json format. You can see below an example of such a json.</p><pre>{ average: 1.2, standardDeviation: 0.8, numberOfElements: 3875 }</pre><p>In this sample the number of elements is the number of users that got to the landing page of the service we are testing, while the average and standard deviation are calculated over the number of successful interactions of each user, i.e. the interactions that reached the specified target. Of course it is also possible for those number to have a different meaning. There’s nothing preventing us, for example, from calculating the required statistics over the amount of each order submitted on an e-commerce or the time spent on the target page by each user.</p><p>Exposing the endpoint we just described is basically the only requirement a custom data source has to meet in order to be used as an Elasticsearch replacement for A/B testing with Vamp Lamia. There are however some more changes we have to make to the Experiment’s configuration in order to specify which data source we want to use. To have a clearer idea of what these changes are are we will refer to the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iLmR_0Qz8XR5QjSH.png" /></figure><p>If you have read our previous blog post, you will notice that the configuration we are using here is very similar to the one used back then. We are configuring the names of the Service and Gateway that the Experiment will use, the time interval of each update and the amount by which the routes weights should be shifted, and, finally, we are defining three Subsets, each one with its own tags or features. In addition to all that, however we are also providing, through the Data Source path field, the uri towards our mock data source. This will allow the Experiment to query it for data at each interval.</p><p>On its own, however, specifying this uri is not enough. As we said earlier, we also have to tell Vamp Lamia to use a different implementation for the Driver responsible for querying Elasticsearch. We are doing that by adding a new key, <strong>complexmetricsdriver</strong>, in the metadata section, with value <strong>custom</strong>. This tells Vamp Lamia to replace the default implementation of the Complex Metrics Driver with the predefined Custom Source implementation, which has the identifier <strong>custom</strong>. That is all.</p><p>Once the form is submitted the Experiment will start and perform the same operations as the previous example, but, this time, all the data will be collected from the mock source we deployed.</p><h3>Conclusions</h3><p>Setting up this example was a useful test for us, because it proved that the goal we set for ourselves while first approaching Vamp Lamia development has been met, that is Vamp Lamia Drivers can be easily replaced in order to change its functionalities. In the future we plan to make use of this feature more and more in order to tackle specific requirements that our customers might have in the future.</p><p>If you are curious about Vamp Lamia and want to check out its features more in depth we invite you to take a look at our <a href="https://github.com/magneticio/vamp2setup">Github repository</a> where you can find a more comprehensive tutorial and try it out on your own. And, of course, keep an eye on our blog for new updates!</p><p><em>Originally published at </em><a href="https://vamp.io/blog/custom-data-source-ab-testing/"><em>vamp.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a4c2e6985c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welch’s t-test for A/B testing with Vamp Lamia and Istio 1.0.2]]></title>
            <link>https://medium.com/@alessandrovalcepina/welchs-t-test-for-a-b-testing-with-vamp-lamia-and-istio-1-0-2-ec0ba86626f3?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec0ba86626f3</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[ab-testing]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Thu, 20 Sep 2018 08:52:50 GMT</pubDate>
            <atom:updated>2018-09-20T08:52:50.327Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*WWyXkvtBDKTMHixX.png" /></figure><p>Welcome back to our ongoing series on the development of Vamp Lamia and our experiences in using Istio for traffic routing on Kubernetes. In <a href="https://vamp.io/blog/ab-testing-istio/">one of our previous posts</a>, we presented our approach to A/B testing with Vamp Lamia through the use of Experiments, which enable the user to quickly create a complex Virtual Service configuration and set up a Policy that will redirect the traffic based on the users’ behaviour, for example moving all visitors to the winning variant of an Experiment. As we stated at the end of the post, however, our implementation was, at that time, pretty simple. Since then, we made quite a few improvements and we are now ready to share them.</p><h3>Welch’s t-test</h3><p>In our initial implementation the outcome of the A/B test was calculated by comparing the ratios of users that would land on a certain target page over the number of users that got to the landing page only. The Subset that achieved the highest ratio would benefit from a progressive increase in the traffic redirected to it until it finally reached 100%</p><p>While this is a sensible approach, it is far from being ideal. Differences in the statistical distributions of the two (or more) sets of user interactions could in fact lead to erroneous results.</p><p>For this reason we decided to use a different method: Welch’s t-test.<br> Welch’s t-test, also known as unequal variances test, is, as the name implies, a statistical test widely employed to verify the hypothesis that two populations of different size and with different variances have equal, or close enough, averages. In order to verify this hypothesis we have to calculate two values. First is the statistic t, obtained through the formula</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/0*f6KvkXIFqErBR7Em.png" /></figure><p>Where X is the average of the population, while s and N are its variance and the number of its elements. Secondly, we need the degrees of freedom, defined as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*QBHPcFT9Cer8XUka.png" /></figure><p>Once we have these two values we can then use them with the t-distribution in order to verify that the averages are close enough.</p><p>This scenario is however a bit simplistic, especially because it compares only two populations. In our case, instead, we might typically find ourselves comparing three or more versions of a given service at the same time and, on top of that, some of these versions might share common features which should be considered individually in the outcome of the test.</p><p>For example we might have three versions of an e-commerce frontend where the first version has a blue background and white text, the second has a white background and red text and the third one has a blue background and black text. Let’s say at the end of the A/B testing the second version is the winner, that means white background and red text is the best combination, however both the first and the third version had a blue background, so their combined results over this feature might actually show that the blue background is overall better than the white background regardless of the color of the text. Our goal is to be able to detect this.</p><p>In order to better showcase how Welch’s t-test is used to implement Experiments in Vamp Lamia, let’s create a simple example and look more closely at how the A/B testing winner will be determined.</p><p>For this example we deployed a nodejs webservice exposing two endpoints that simply acknowledge all requests. We have three different versions of this webservice and thus a separate subset for each version. As already shown in the previous blog post we also set up a Service, Destination Rule and Gateway to allow access to our webservice. After doing all that we can now create the Experiment itself as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hJFRcMZlYR7y1XjQ.png" /><figcaption>Experiment configuration</figcaption></figure><p>Once the experiment has been created and the first minute has expired a running instance of Elasticsearch will be queried for the metrics of each subset and the data thus gathered will be used to calculate the Welch’s test result.</p><p>More specifically these are the steps that will take place:</p><ul><li>Number of elements, average and variance get gathered from Elasticsearch</li><li>For each Tag the Welch t-test hypothesis gets evaluated against the aggregated values of the other tags.</li><li>If the averages are comparable the highest average gets identified.</li><li>The results of the test are aggregated per Subset based on the tags associated with each subset.</li><li>Subsets that obtained a positive score get a weight increase, while all others get a weight decrease.</li><li>The new routing weights thus obtained are normalised so that their sum doesn’t exceed 100%.</li></ul><p>This, in short, is how the Experiment will calculate statistically relevant result to identify the best Subset among those configured for our service.</p><h3>Conclusions</h3><p>This new way of handling A/B testing in Vamp Lamia can, of course, still be improved, for example by providing more details about the test outcome and about how each of the features actually performed. In addition to that, we are also planning to add more configuration options and make the creation of Experiments more intuitive and straightforward. Nonetheless we believe this shows the potential in using Istio in combination with Vamp Lamia to handle complex A/B testing scenarios. We hope the example we presented piqued your interest and, if that’s the case, we invite you to visit our <a href="https://github.com/magneticio/vamp2setup">Github repository</a>, download Vamp Lamia test version and take a look at the extensive readme to try it out for yourselves . If you have any suggestions or feedback, please let us know. We look forward to hearing what you think. See you soon with a new blog post!</p><p><em>Originally published at </em><a href="https://vamp.io/blog/welch-ttest-ab-testing-istio/"><em>vamp.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec0ba86626f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Networking with Istio on Kubernetes]]></title>
            <link>https://medium.com/vamp-io/advanced-networking-with-istio-on-kubernetes-39f1e6eb0c39?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/39f1e6eb0c39</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[istio]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Wed, 18 Jul 2018 11:33:12 GMT</pubDate>
            <atom:updated>2018-07-18T11:45:17.318Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F05sDjQWQ0-YiDZ22RMSsQ.jpeg" /></figure><p>Welcome to the third post in the ongoing series describing our experiences in adopting <a href="https://istio.io/">Istio</a> and the development of Vamp Lamia. For more details on what we are trying to achieve with Vamp and why we choose Istio, please refer to our <a href="https://medium.com/vamp-io/putting-istio-to-work-8513f5218c51">first</a> and <a href="https://medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2">second</a> posts.</p><p>Up till now we focused mostly on presenting specific features of Vamp Lamia by relying on examples that were far simpler than most real world scenarios.</p><p>In this post we will present a more complex example, based on a test setup that we used internally to verify the extent of Istio’s capabilities. To that end we will create multiple Services, Virtual Services and Gateways and we will present Vamp Lamia solutions to the problems that might arise when managing such an environment.</p><p>While reading through this post, keep in mind that a more complete guideline to reproduce this setup on your own cluster is available our <a href="https://github.com/magneticio/vamp2setup/tree/feature/advanced-networking-example#advanced-networking">github repository</a>.</p><p>A typical scenario that would benefit from the described topology with multiple Virtual Clusters and multiple Gateways, would be the following one:</p><p>Multiple independent teams working on their own services with a “<a href="https://queue.acm.org/detail.cfm?id=1142065">you build it, you run it</a>” approach, where the sizing and budgets of the infrastructure are not clear yet, and thus running multiple Virtual Clusters on a single “real” Cluster makes more sense at this moment. The teams develop, iterate and deploy their services themselves and independently from each other, the services sometimes need to connect to each other or to other external services.</p><p>Let’s say team 1 is managing an old Service svc-1, which has gone through many iterations and versions, is EOL, but cannot be decommissioned yet. Additionally Service svc-1 is exposed on two different hostnames that correspond to different versions of the same Service.</p><p>Team 2 is developing a Service svc-2 that has the same endpoints as the old Service svc-1, but also needs new features and other changes that extend its functionalities. Because other services also make use of service svc-1, it is decided to not change its interface at this moment. Team 2 then has to route traffic between svc-1 and svc-2 based on the endpoint that is being invoked.</p><p>Team 3 makes use of this new Service svc-2 interface, but also needs to make use of caching or SSL features. This means that traffic needs to go outside of the cluster in order to connect to the Service.</p><p>This rather complex scenario is outlined in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SRRQKjtceX_u39bIyrMvzA.jpeg" /></figure><p>As you can see, for each team we have a different Virtual Cluster (corresponding to a namespace in <a href="https://kubernetes.io/">Kubernetes</a>) with its own Deployments. When the namespaces and Deployments are first created in Kubernetes, Vamp takes care of importing them automatically into its internal representation, leaving us with the task of setting up the Networking Infrastructure made up by Services, Virtual Services and Gateways.</p><p>The first problem we have to face is how to manage Gateways. Gateways are Istio resources that allow to expose Services outside the Cluster. The standard approach with Istio is to have a single Gateway mapping all required hostnames, however, while this is certainly an acceptable solution in a lot of cases, it doesn’t fit our scenario. We don’t want the separate teams to have to worry about a shared resource that contains all hostnames, we want instead to have a separate Gateway for each team.</p><p>Achieving this can be a rather difficult task in Istio, but with Vamp Lamia’s support it is as easy as filling in a form, like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-dMWuBYX3M1lk5G0FNF77w.png" /><figcaption>First gateway setup</figcaption></figure><p>When the form is submitted Vamp Lamia will create a Load Balanced Service and the corresponding Deployment to allow the new Gateway to have its own IP address and thus avoid conflicts with other Gateways.</p><p>Now that we decided how to expose the Services, we need to take care of the routing: we will do that by employing Virtual Services.</p><p>In the first Virtual Cluster (vamp-test1) we want to have one service and dispatch requests to its different Subsets based on the hostname.<br>To do that we first need to create the Service and its Destination Rule, mapping each version to a different Subset. After that is taken care of, we can create two Virtual Services with the following configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUoVNnQsl3-oQW6QDhs34g.png" /><figcaption>First Virtual Service</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtgFfCxrQzYrfVFz3utK8Q.png" /><figcaption>Second Virtual Service</figcaption></figure><p>In the hosts field we have specified different hostnames, the same we specified also in the Gateway definition. This will prompt the Virtual Services to filter requests based on the hostname and only handle those matching the specified value. Mind the fact that hostnames are not automatically assigned to the Gateway ip. but you can easily do that by using <a href="https://developers.google.com/speed/public-dns/">Google DNS</a> or other online services like, for example, <a href="https://www.name.com/">name.com</a> or <a href="https://www.dnsdynamic.org/">DNSDynamic</a>.</p><p>It’s now time to move to Virtual Cluster vamp-test2. In this Virtual Cluster we want to route request to Services svc-2 or svc-1 based on their URI. First of all let’s create a second Gateway with a single hostname.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SsVvxIXaouqDP2ItsMrGlw.png" /><figcaption>Second Gateway</figcaption></figure><p>Now we can achieve our goal by creating a new Virtual Service, where we set up two conditional rules, filtering requests based on the URI prefix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SpSdCwvsMGsPbBC4fVfEaw.png" /><figcaption>Third Virtual Service</figcaption></figure><p>With this configuration URIs matching the specified pattern will be forwarded to the appropriate service and the URI itself will be rewritten to “/”. Mind the fact that since svc-2 resides in another Virtual Cluster we have to use its fully qualified name in order to reach it.</p><p>Finally let’s say our third imaginary team of developers needs to reach for the Virtual Service we just defined from outside the Cluster. This would be more logical if we had a second Cluster on which the third team would be working, but, for the sake of simplicity, we will just use another Virtual Cluster (vamp-test3).</p><p>External services are normally not reachable from pods belonging to the Istio Mesh, hence we have to somehow make the host defined on Gateway gw-2 accessible. Service Entries are an Istio resource that can do just that.<br>We are thus going to create one of them with this configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_SplKo6sSKYC9h8NF-jhQ.png" /><figcaption>Service Entry</figcaption></figure><p>This will allow us to make calls towards the Service (for example by logging into the single pod in vamp-test3 and running CURL commands). Additionally we can now also add a Virtual Service on top of the Service Entry to take advantage of some features like retries or timeouts. In this case the Virtual Service configuration is quite simple, because there is no need to specify subsets or ports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NiWJAHTawe-Flgn1pzgYw.png" /><figcaption>Fourth Virtual Service</figcaption></figure><p>With this final step we have achieved our initial goal. We managed to provide all three teams with their own independent working environments, to expose their services according to different needs and to consume them as if they were external service.</p><p>In doing that we learned how to properly set up Gateways and the different roles that Virtual Services can play in handling the networking layer of a Cluster. Moving forward, we plan to support more advanced configuration options for all the resources used in the example and to make setting them up through Vamp Lamia even simpler.</p><p>This concludes our example, but don’t forget that if you want to delve deeper or experiment with a setup of your own, you can refer to our <a href="https://github.com/magneticio/vamp2setup">github repository</a>, where you will find the complete tutorial for this example as well as many other guides.</p><p>Check back soon for more updates on our experiences with Istio and the Vamp Lamia’s new features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39f1e6eb0c39" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vamp-io/advanced-networking-with-istio-on-kubernetes-39f1e6eb0c39">Advanced Networking with Istio on Kubernetes</a> was originally published in <a href="https://medium.com/vamp-io">vamp.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A/B testing on Kubernetes with Istio 0.8]]></title>
            <link>https://medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2?source=rss-aa341345104b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6323efa2b4e2</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Alessandro Valcepina]]></dc:creator>
            <pubDate>Thu, 05 Jul 2018 08:15:57 GMT</pubDate>
            <atom:updated>2018-07-05T08:15:57.943Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*SEDs0n1m8vhTPlxOhrudJA.png" /></figure><p>This is the second post in our ongoing series describing our experiences in adopting Istio for traffic routing on Kubernetes. For more details on what we are trying to achieve with Vamp and why we choose Istio, please refer to our <a href="https://medium.com/vamp-io/putting-istio-to-work-8513f5218c51">first post</a>.</p><p>The last months have been rather exciting for the Istio community. With the release of version 0.8 the platform has become more stable and is now benefitting from a more consistent, albeit still rough, design. These improvements come however at the price of a greater complexity in the configuration of routes.</p><p>Our goal with this new version of Vamp Lamia has been both to migrate to Istio 0.8 from 0.7.1 and to make it’s usage far more simple. At the same time we wanted to provide a new feature that would help with a specific real life scenario.<br>Nowadays, many product managers want to test the value of new features on a page by means of A/B testing. Unfortunately this is often far from easy.<br>Usually people end up with complex systems, feature switches or logging systems with offline processing. More often than not, all of this relies on manual intervention, making it a slow, error prone process, that also doesn’t integrate well with CI/CD pipelines.</p><p>As we set out to work, we asked ourselves: how much of this can be done automatically, without any coding at all?</p><p>Enter Vamp Lamia 0.2.0 .</p><p>Central to our approach to solve this problem is the concept of an Experiment.<br>Experiments are an easy way to setup cookie based A/B testing on services managed by Vamp Lamia. They only require a very basic configuration and no coding at all.<br>For the sake of simplicity, let’s assume you have an e-commerce website and you’ve heard that customers buy more if the background of the page is blue while your current background is red. You want to test this hypothesis and move to the blue background if this proves true in a canary releasing manner.</p><p>In order to do this you will have to deploy the two versions you want to test and tag them, for example, as “version1” and “version2”. Vamp will pick up these two deployments and allow you to create a Service, as well as a Destination Rule and a Gateway bound to it.<br>A detailed explanation of the role played by these entities is beyond the scope of this post and you can find more information in the <a href="https://istio.io/docs/">Istio documentation</a>.<br>For now, it suffices to say that a Gateway is the Istio equivalent of a Kubernetes Ingress and thus allows for the service to be exposed externally, while the Destination Rule maps labels on your deployments to subsets, providing an abstraction that can be used to better group different versions of your service.<br>As you can see in the screenshots below, setting up these resources is straightforward with just a few, easy to understand parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PP5sAruEiaScSLOAfPB5ag.png" /><figcaption>Service setup</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WAKB46rHvN-9qDtFvNOtQ.png" /><figcaption>Gateway setup</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LkGPB6j0HmOYTS5Mpk4MAA.png" /><figcaption>Destination Rule setup</figcaption></figure><p>Once this is done you can start setting up the Experiment itself, for example using the configuration shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SlV79_8kbprKbbutXp7Spg.png" /><figcaption>Experiment setup</figcaption></figure><p>Most of the fields are self-explanatory, but, for the sake of clarity, let’s got through them anyway:</p><ul><li><strong>Service Name</strong> is the name of the Service on which you want to run the A/B testing.</li><li><strong>Service Port</strong> is the Service port to use.</li><li><strong>Gateway Name</strong> is the Gateway through which the Service will be exposed.</li><li><strong>Period in minutes</strong> is the time interval in minutes after which periodic updates to the configuration will happen.</li><li><strong>Step</strong> is the amount by which the weights will shift at each update.</li><li><strong>Tags</strong> is a descriptive value associated with the specific version of the service.</li><li><strong>Subset</strong> is the subset of the Service.</li><li><strong>Target</strong> is the URL that should be checked to assess the success rate of a specific Subset.</li></ul><p>The Experiment will test the performances of a feature by checking the number of users who opened the target page after reaching the landing page. <br>To track this, Vamp Lamia sets a cookie for every user who visits a landing page and later checks whether the same user visited the target page.<br>All this can be achieved thanks to the fact that, once an Experiment is created Vamp Lamia takes care of setting up a new Virtual Service bound to the provided Service and Gateway.</p><p>A Virtual Service is the Istio 0.8 replacement for Route Rules and is used to define traffic routing for the specified Service.<br>You can check out its configuration in the following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VxrlhZT4_ReuZBzaasNVg.png" /><figcaption>Virtual Service configuration</figcaption></figure><p>We realise this configuration can feel rather obscure, so let’s walk through it together.</p><p>The Virtual Service defines three routes. The first two are easy to understand: they each lead to one of the deployed versions. The third one is evenly load balancing between two versions of a Cookie Server.<br>The purpose of this configuration is to direct new visitors towards the Cookie Server which will then set cookies identifying them as a specific user and assigning them to one of the configured subsets.<br>Once this is done, the Cookie Server redirects the user back to the original URL and, thus, back through the Virtual Services. This time, however, having a Subset Cookie, one of the conditions set on the first two routes applies and the user is forwarded to a specific version of the landing page. This is done using a standard HTTP redirect, so the overhead is low and users don’t experience any interruption.<br>Also, thanks to our reliance on cookies, we are able to provide users with a consistent experience while continuing our test, meaning that subsequent requests coming from the same user in a short period of time will always go to the same version.</p><p>Depending on the test results, the policy defined on the Virtual Service will then move more users to the more successful version, i.e. versions with a better ratio of users that reached the target over the total number of users that reached the landing page.<br>Let’s assume, for example, that the blue page is better for most customers. While initially customers will be split evenly among the two versions, as time goes by and results come in, the traffic will be shifted. More customers will be assigned cookies leading to the blue page and, since cookies are time limited, also customers that had been previously assigned to the red page, will gradually move towards the better performing version.</p><p>Let’s assume, for example, that the blue page is better for most customers. While initially customers will be split evenly among the two versions, as time goes by and results come in, the traffic will be shifted. More customers will be assigned cookies leading to the blue page and, since cookies are time limited, also customers that had been previously assigned to the red page, will gradually move towards the better performing version.</p><p>This behaviour can be monitored through the metrics page as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbWOYP-7vpSoyjsYmVZ8aQ.png" /><figcaption>Virtual Service metrics</figcaption></figure><p>The scenario presented here is of course still oversimplified. In the coming weeks we will move away from the concept of subset and version in order to focus more on features that the user wants to test and we will switch to <a href="https://en.wikipedia.org/wiki/Welch%27s_t-test">Welch’s t-test</a> algorithm to identify the best performing versions. At the same time we plan to automate also the creation of Gateways and Destination Rules, so that all that complexity can be hidden if the user has no need for specific configurations.</p><p>That’s all for this time! Please feel free to give us your feedback on this new feature and the direction in which Vamp Lamia is evolving and don’t forget that, if you want to have a more in — depth description of Vamp Lamia features you can take a look at our repo on <a href="https://github.com/magneticio/vamp2setup">github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6323efa2b4e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2">A/B testing on Kubernetes with Istio 0.8</a> was originally published in <a href="https://medium.com/vamp-io">vamp.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>