<?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 Brian Branch on Medium]]></title>
        <description><![CDATA[Stories by Brian Branch on Medium]]></description>
        <link>https://medium.com/@reisuj?source=rss-517d1ca3e9af------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_sSKFPOpYDvdbIYE5HPusA.jpeg</url>
            <title>Stories by Brian Branch on Medium</title>
            <link>https://medium.com/@reisuj?source=rss-517d1ca3e9af------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:05:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reisuj/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[Mastering 2D Movement Constraints in Unity]]></title>
            <link>https://reisuj.medium.com/mastering-2d-movement-constraints-in-unity-e9c961e39c80?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9c961e39c80</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Wed, 01 Jan 2025 15:46:58 GMT</pubDate>
            <atom:updated>2025-01-01T15:46:58.659Z</atom:updated>
            <content:encoded><![CDATA[<p>When developing 2D games in Unity, controlling player movement is essential for a polished and enjoyable experience. As I revisited my earlier articles and courses with GameDevHQ, I realized there were key movement techniques I hadn’t shared — let’s fix that..</p><p>In this case I’m adding how to create constraints for the players movement from my original article on <a href="https://medium.com/@reisuj/simple-player-movement-ed5d5e899ea">Simple Player Movement</a>.</p><p>The goal was to keep the player from going offscreen below and to keep them from going further than about halfway in the up direction. I also wanted to have the player wrap to the other side when going left or right off screen. Restricting the player’s vertical movement ensures they stay within the play area, and preventing them from going off-screen.</p><figure><img alt="Image of Player primitive cube going off screen in different areas." src="https://cdn-images-1.medium.com/max/639/1*Hfmo-En9_yHP75wfQWXiSg.gif" /></figure><p>This is definitely not what I want the player to do. I’ll start with restraining movement on the y-axis. What I need is to check if the player is above or below a certain amount and then stop them from going further. I can use if-then-else statements to do this. I’ve checked the Y position where I want to set the limit which will be between -4 and 1, so I’ll write out the if-then-else statements like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h8q4Ku6OkPtvbLTYiRK8Uw.png" /><figcaption>If-then statements to constrain the player movement on the y-axis.</figcaption></figure><p>So I check if the player is above or below these values and then set the transform.position to those values using a new Vector3. And now the player is prevented from going off-screen below and restrains them to about half of the screen going up. You can see this in action below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*ifrThbu9khl3kRQ6hpUtJQ.gif" /><figcaption>Player cannot go below screen or past halfway moving up.</figcaption></figure><p>The next order of business is to have the player wrap around when going off screen to the right or left. having the player wrap from side-to-side is very common in space shooter games. It allows the player to appear on the opposite side when they go off-screen.</p><p>It will be similar to how I did the restraining for up-down movement but this time I’ll want the player to change to the other side when going off screen to the left or right. I determines that on the left it will be about -11.3 and to the right it will be about 11.3. I used the below code to accomplish this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHjNMP-k806ffppCtT8OzQ.png" /><figcaption>Code to wrap the player when going off screen to the left or the right.</figcaption></figure><p>Now as shown below the player is wrapping when going off screen to the left or the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*81N5M9ew8MvmdxBZJJ_lbw.gif" /><figcaption>Player wrapping when going off screen to the left or the right.</figcaption></figure><p>Going back to the vertical restraining, there is a different way that I could do this. Unity has as function called Mathf.Clamp, what this does is clamp a result between two chosen values. If I used this instead I could accomplish the same thing but with only a single line of code instead of a full if-then-else statement.</p><p>While either way would work, using Mathf.Clamp helps keep the code simpler and makes it easier to maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*siOJlDwyG-BZwlP2_5SI4Q.png" /><figcaption>The above code keeps the player’s X and Z positions while clamping the Y position between -4 and 1.</figcaption></figure><p>What the code above does is maintain the transform position on the x-axis, but on the y-axis the Mathf.Clamp function restrains the values from going below or above the values of -4 and 1 which are provided.</p><p>And this works just like before but with less code. Now we have the player restrained on the y-axis and wrapping on the x-axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*BqW6vcRDcGI3Q0RzWZLWPA.gif" /><figcaption>Player now restrained on the y-axis and wrapping on the x-axis.</figcaption></figure><p>If you found this useful, keep an eye out for more as I continue updating some missed information and also providing some new insights in to C# and Unity Development. Please leave a comment if you found this helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9c961e39c80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Setting up the Elevator, Part 4]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-4-8bb79d5871df?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bb79d5871df</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Thu, 07 Oct 2021 21:31:46 GMT</pubDate>
            <atom:updated>2021-10-08T07:44:20.835Z</atom:updated>
            <content:encoded><![CDATA[<p>In this final part of setting up the Elevator, I’ll have it go back up when the Player presses the “E” key a second time after boarding the Elevator.</p><p>The first thing I’ll do is change the CallElevator() method to work as a toggle instead of assigning the _goingDown value to true. I can do this by setting it to _goingDown = !_goingDown. This will switch it between true and false when the method is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*iczrC_M4M4F3uU_MPcZt8A.png" /></figure><p>Next, in the FixedUpdate() method, I need to set the Elevator to go back up to the Second floor if _goingDown is false. I do this by adding an else if statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fqOkAKNOh2Xvm4gi5Ajmg.png" /></figure><p>Now the Elevator will come down and go back up with the Player.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*X85m9YBZ2VtKTcpaV_RZFA.gif" /></figure><p>That completes the fourth and final part of setting up the Elevator. Next, I’ll be setting up wall jumping, so make sure to check the next article.</p><p>And until next time, I wish you well on your coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bb79d5871df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-4-8bb79d5871df">2.5D Platformer: Setting up the Elevator, Part 4</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Setting up the Elevator, Part 3]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-3-f24072ae27dd?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/f24072ae27dd</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Tue, 05 Oct 2021 20:07:32 GMT</pubDate>
            <atom:updated>2021-10-06T06:41:34.237Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will have the Elevator move down to the Player when the call button is pressed.</p><p>I’ll start by creating a script named Elevator and adding it to the Elevator Gameobject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*z5dbVyX-9rTP--_s9wyE-Q.png" /></figure><p>Within the Elevator script, I create a method that will be used to call the Elevator named, intuitively enough, CallElevator(). This method will be called when the Call Button on the Elevator Panel is pressed.</p><p>I do this by creating a Serialized private variable of the type Elevator named _ Elevator.</p><p>I then drag the Elevator GameObject into the appropriate space in the Inspector for the Elevator_Panel GameObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*5ccmS9ZUfYsIlIjfy7fJ3g.gif" /></figure><p>Now, I can add a statement to call the CallElevator() method when the “E” key is pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sOEUnItlmBl3P9o-c2o5A.png" /></figure><p>What’s left is to program the Elevator movement into the CallElevator() method.</p><p>I’ll first create two duplicates for the Elevator GameObject and name one SecondFloor and the other FirstFloor. Then, I’ll leave the second floor at the same location and move the FirstFloor down to the lower level. Then I’ll remove all of the components except for the Transform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r31AdQYs47TeZXeRRUeehw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*uY42PxumShBecMBa-gbBWQ.gif" /></figure><p>In the Elevator script, I’ll create a boolean variable named _goingDown, which defaults to false, and two Serialized Transform variables named _secondFloor and _firstFloor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*nv9PmL5wOfnmxiWRwEFNhg.png" /></figure><p>Once I save and go back into Unity, I’ll drag the GameObjects FirstFloor and SecondFloor into the correct places in the Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Dr8JwRWM1ijdX_WuacM8Fg.gif" /></figure><p>Now I’ll create a FixedUpdate() method and, using an if statement, check the value of _goingDown and move the Elevator appropriately using Vector3.MoveTowards(). I’ll also create a float called _speed to control how fast the elevator moves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MemX7YKqHHBrw0zGemVUUw.png" /></figure><p>When pressing the Call Elevator button, the Elevator will move down as long as we have enough coins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*AJVNCYGXBPAPv_WCCmcOQw.gif" /></figure><p>In the next article, I’ll set up the behavior for the Elevator to go back up when the Player presses the “E” key again.</p><p>Until then, as always, I wish you the best on your gamedev and coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f24072ae27dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-3-f24072ae27dd">2.5D Platformer: Setting up the Elevator, Part 3</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Setting up the Elevator, Part 2]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-2-ef59c46100fb?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef59c46100fb</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Mon, 04 Oct 2021 19:45:39 GMT</pubDate>
            <atom:updated>2021-10-06T06:41:36.817Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I continue the setup for the elevator in the 2.5D Platformer. In the previous <a href="https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-1-31b6bb56f35d">article</a>, I went over having the Player press the elevator button when they are in range and changing the button when pressed.</p><p>This time I’ll be adding an additional requirement for the Player to have collected 8 “coins” for the button to work.</p><p>This is actually fairly straightforward to accomplish. But, first, I need a method on the Player script that will return how many coins the Player has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*i7zQEHc0Br9XKprVYkyTfA.png" /></figure><p>In the ElevatorPanel script, I need to get a reference to the Player script using GetComponent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*rclqmv4SxbPMeZbsQvU1kg.png" /></figure><p>Then when I check if the “E” key has been pressed, I add an additional check to see if the return from calling the above method is greater than or equal to 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cH5gpbFH1pt58DIMaIOyw.png" /></figure><p>Now the Player can only press the Elevator button if they have at least 8 coins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*ddee9tJ79yzaF2RHuI3YUQ.gif" /></figure><p>This was a pretty short one. In the next article, I’ll actually set up the functionality to call the elevator and have it move down to the Player.</p><p>Until then, I wish you well on your own coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef59c46100fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-2-ef59c46100fb">2.5D Platformer: Setting up the Elevator, Part 2</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Setting up the Elevator, Part 1]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-1-31b6bb56f35d?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/31b6bb56f35d</guid>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Fri, 27 Aug 2021 22:45:30 GMT</pubDate>
            <atom:updated>2021-08-28T09:51:08.799Z</atom:updated>
            <content:encoded><![CDATA[<p>In the next couple of articles, I’ll set up an elevator that the Player will call by pressing the “E” key near an elevator call panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*Ty5qZ9MRneNxwHFZthpVRQ.png" /></figure><p>First, I’ll be setting up the behavior of the panel. For example, I want the button to change color when the Player presses the “E” key, and also, I only want the “E” key to work if the player is near the elevator panel.</p><p>To detect when the Player is in front of the panel, I’ll use a Box Collider. Then in a script that I’ll add to the Elevator_Panel GameObject, I’ll use an OnTriggerStay() event to check if the Player is within the area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*vGo_3N3MedtqaaVKxOxxNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*2mfqutWOSL0OohPuZIByMQ.gif" /></figure><p>Now that I have the script on the GameObject, I will create an OnTriggerStay() event, check if the collider is tagged as the Player, and check if the E key is pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*j4weI02rVtNmEGgG8M42Pw.png" /></figure><p>Next, to change the button&#39;s color, I’ll need to create a variable to reference it and then drag the object into the Inspector. I’ll create a variable of type Meshrenderer since that will give me direct access to the material then the object&#39;s color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*tF_ZnlOSsUY87okWqLKMXg.png" /></figure><p>Now I need to drag the Call_Button object into the Inspector to access it further in the script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*J_QPvscHj5pFAZUjPlbZfQ.gif" /></figure><p>Finally, to change the color of the Call_Button, I need to go into the script and add the line to change the color when the E key is pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*MG7wMMb5JdB4jukpfsprGw.png" /></figure><p>When Igo in front of the elevator panel and push the E key, the button will turn green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*Xi7aQ9srXAhFHYNhyZ9n1g.gif" /></figure><p>That is it for the first part of setting up the elevator. Next article, I will add another requirement for the Player to have collected 8 coins for the elevator button to work.</p><p>So until next time, I wish you well on your own coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31b6bb56f35d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-setting-up-the-elevator-part-1-31b6bb56f35d">2.5D Platformer: Setting up the Elevator, Part 1</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Adding Lives Display and Respawn]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-adding-lives-display-and-respawn-aa17d70d1fbf?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa17d70d1fbf</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 15:33:13 GMT</pubDate>
            <atom:updated>2021-08-27T16:59:40.133Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I’ll add a lives display to the game and have the Player respawn when they fall off a platform.</p><p>First, I’ll create a variable for lives in the Player script and set it to 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wy_JSb_Unv3YZNzrd2dyfA.png" /></figure><p>Then I’ll duplicate the Coin Text under the canvas and change the name to Lives and change the text in the textbox to “Lives:”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*ICOQeBMrP7ue3yJ9Sc9dvg.gif" /></figure><p>Then I can move it up above the Coins in the UI window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*tJMpYpCQmR-wHctR99Ud5w.gif" /></figure><p>Next, in the UIManager script, I’ll add a reference to the Lives text and create a method to update the Lives display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*DxtE6adOk1dEP-GEHnm1Vw.png" /></figure><p>Then in the Start() method of the player, right after I null check the UIManager, I’ll call the UpdateLivesDisplay() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*LQlY7AML6EHaLfBtvkdqaw.png" /></figure><p>Also, I need to drag the Lives GameObject into the Lives Text for the UIManager in the Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*w0vv5r7pPmouvYMQ0kcosQ.gif" /></figure><p>That sets up the UI element for the Lives display.</p><p>Next, I needed to create a way to detect when the Player has fallen off of the playing field. To do this, I created a 3D cube and scaled it on the X-axis to about 10. I then changed its name to Dead_Zone and set it as Is Trigger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZwaDWQRPEmnbukx2rXtbA.png" /></figure><p>O also created a script called DeadZone to attach to the Dead_Zone object. Since I hadn’t decided how far I was going to make the platformer, I wanted to make the Dead_Zone follow the player along the X-axis so that I could build the level infinitely in either direction along the X.</p><p>To do this, I created a serialized Transform on the DeadZone script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*4YYvg973vcB9a3TBfUXC6w.png" /></figure><p>Then in the Update() method, I have the Dead_Zone follow the player on the X-axis while keeping its own Y and Z.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7hkqeLHGdU-Y_RnIB6OmA.png" /></figure><p>Then I just needed to drag the Player gameobject into the appropriate place in the inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*vdtTX45hBxwJMAfhsqP7IQ.gif" /></figure><p>Now it’s time to have the Dead_Zone detect the Player. I do this by setting up an OnTriggerEnter() event in the DeadZone script and checking if the object is the Player. If so, I’ll call a method on the Player named PlayerDied().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*O5AvqNwYzIAVFCdW1Gd-Gg.png" /></figure><p>Now, in the PlayerDied() method, I’ll decrement the Player’s lives and call the method on the UIManager to update the lives. Then I’ll check if the Player has zero lives left. If so, I’ll restart the level. Otherwise, I’ll spawn the player back at their spawn point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7cAAP2Sja8hzMt8Ka7sQQ.png" /></figure><p>Now, this almost finishes the respawn and lives counter section. But there is a small problem. It looks at if the Player is moving too fast to have their position reset when they fall. So what I will do is turn off the CharacterController component first thing when the PlayerDied() method is called. Then I’ll create a co-routine to wait .1 seconds before enabling the Character Controller again. The co-routine will be called right after the player is respawned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gooehqCk6NyCG533OTWY4Q.png" /></figure><p>And below is the co-routine that will be called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2TnqptrhVbeZHo4zyG4EA.png" /></figure><p>Now the Player will respawn when they die, and the game will restart at zero lives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*PcQyoEF-etZWzQ3R1OY_XQ.gif" /></figure><p>I hope you enjoyed this article, and make sure to check out the next where I’ll start setting up some puzzle elements for the game.</p><p>And as always, I wish you the best on your coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa17d70d1fbf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-adding-lives-display-and-respawn-aa17d70d1fbf">2.5D Platformer: Adding Lives Display and Respawn</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Moving Platforms, Part 2]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-moving-platforms-part-2-2bbe46c9da9e?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bbe46c9da9e</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Sat, 21 Aug 2021 23:01:11 GMT</pubDate>
            <atom:updated>2021-08-27T16:59:42.740Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part of the article, I’ll be fixing a small problem with the Player on the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*g8u5ff9YhVDpkKozFmP-8g.gif" /></figure><p>You can see that the Player does not move with the platform, and if I do not move the Player, it will slide off of the platform. To fix this, I’ll have the Player set as a child of the platform when on the platform, then unparent it when jumping off.</p><p>First, I’ll add a second box collider to the Moveable_Platform, adjust it up just a little bit, and set it to Is Trigger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*8R-3i1hZR0dWEddw7DLweA.gif" /></figure><p>Now in the MovingPlatform script I’ll need to add a check for OnTriggerEnter() and OnTriggerExit(). On the OnTriggerEnter(), I’ll check if the collision is with the Player. If so, I’ll set the player’s parent as the platform. Then in OnTriggerExit(), I’ll check if the object leaving is the player, and if so, I’ll set the player’s parent to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*vr__DTW3-390xKexh4I1Ag.png" /></figure><p>Now the Player should stay on the Platform and jump off with no problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*zFIN25Bh5EcF0pBqcZMkUw.gif" /></figure><p>Now it’s working as it should. As a bonus to this part of the article, I’m also going to show how I modularize the moving platform to be re-used easily.</p><p>First, I will create a new empty object named Moving_Platform, and reset its Transform to zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6N7mXX_WuylU6WIFMAThIA.gif" /></figure><p>Then I’ll move the Moveable_Platform, Target_A, and Target_B into the empty Moving_Platform and change their Transforms to zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-fyNs8MQxCA_WSi21wrf9w.gif" /></figure><p>Now I can drag the Moving_Platform into the Prefabs folder, and I can then add more of them as needed. When I add them into the scene, a designer or I can set where they want Target_A and Target_B to be placed, and the platform will move between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*0EqSGeLGqVaMGmCaNFvIOQ.gif" /></figure><p>You can see above I know have three moving platforms placed, all of which are in different directions.</p><p>I hope you enjoyed these articles, and make sure to check back for the next one, where I’ll be setting up a lives counter, and a respawn if the Player falls off of a platform.</p><p>As always, I wish you the best of luck on your own coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bbe46c9da9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-moving-platforms-part-2-2bbe46c9da9e">2.5D Platformer: Moving Platforms, Part 2</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Moving Platforms, Part 1]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-moving-platforms-part-1-48458db4e8ed?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/48458db4e8ed</guid>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Sat, 21 Aug 2021 11:02:27 GMT</pubDate>
            <atom:updated>2021-08-27T16:59:44.728Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll create movable platforms that can provide an extra challenge to the Player.</p><p>I’ll first rename one of the platforms to Moveable_Platform and make 2 duplicates of the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzRb0dnKILJrwG9gPuZCoA.gif" /></figure><p>Next, I’ll rename the 2 duplicates to Target_A and Target_B. These will serve as the two points that the platform will move between, so I’ll move them to where I want to platform to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_lM-M6TMrkmjMgLoUd_nA.gif" /></figure><p>Now I’ll select Target_A and target_B and remove their Mesh Filter, Mesh Renderer, and Box Collider since I only need their Transform component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*kjetsrh8Pwiz6bhktcmazw.gif" /></figure><p>Next, I’ll create a script and name it MovingPlatform. Finally, I’ll attach this script to the Moveable_Platform object. This script will control the movement of the platform between Target_A and Target_B through code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*GlPFnEALl1J5y8RPCFDRlQ.gif" /></figure><p>To have the platform move between Target_A and target_B, I’ll need to get a reference to those two points. To do this, I’ll create a Transform variable for each point and Serialize them so I can drag them into the Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*0MsIFsPP-TzMhiBNBO2V3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*WFA63VM9jscED-_qdJpOEA.gif" /></figure><p>Because I’m dealing with physics movement, I will do the calculations and movement in a FixedUpdate() method instead of Update(). This will provide a more measured and consistent timing to the movements involving physics. I’ll also use a unity method called MoveTowards() to have the platform move to each point.</p><p>I only want to platform to switch directions when it reaches each respective point. So I’ll create a private bool named _switching and use that to check if the platform has reached a point and if so, I’ll send it in the other direction and change the state of _switching.</p><p>So first, I set up the moving code based on whether _switching is true or false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkGzhvX_nPobvI_SbeOEEA.png" /></figure><p>Then I add conditionals to change the value of _switching when the platform reaches either target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLgwEKpI9JPkczNcpl3BvQ.png" /></figure><p>This gives us a nice consistent moving platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*inrHgdMxkS054KjziepW2Q.gif" /></figure><p>That’s it for Part 1 of the article dealing with the moving platform. In Part 2, I’ll take care of a little problem when the Player actually jumps onto the moving platform.</p><p>I hope you found this interesting and informative. And until next time, I wish you all the best on your coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48458db4e8ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-moving-platforms-part-1-48458db4e8ed">2.5D Platformer: Moving Platforms, Part 1</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Collectibles]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-collectibles-6cbf47ab7d66?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cbf47ab7d66</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Fri, 20 Aug 2021 22:02:29 GMT</pubDate>
            <atom:updated>2021-08-27T16:59:46.607Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll be setting up the spheres we have to be collected by the player and setting up a UI display to show how many have been collected.</p><p>The first thing I did was to create a UI Text object named Coins. I then changed the text body to Coins: 0 and placed it in the upper left corner of the game screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4C4op3sfNhTnR9XPBSyVNw.png" /></figure><p>Next, I created a script named Collectible, which will be used for all collectible objects in the game. I also renamed the spheres to Coins in the Hierarchy and made them a prefab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-iNw62oCpZP6X9j9Bh47g.png" /></figure><p>Now it’s time to jump in and start scripting the behavior for the collectibles, the text object, and the player. First, I’ll start with the Player script by adding a variable to keep track of the coins the Player has and a method AddCoin() which will be called from the coin when the player collects it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*iL36kFBarI8eVVrRJ99Fjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*5W4gUefddSjQFSstVWVtdQ.png" /></figure><p>Then I’ll move over to the Collectible script. There I need to add an OnTrigerEnter event and check if the collision is with the Player. If so, I get a handle to the Player script, null check to be safe, call the AddCoin() method, then destroy the GameObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8-9Axo-QkPuvdr8UTeQ8Q.png" /></figure><p>Next, it’s time to set up a UIManager script on the Canvas GameObject. The UIManager will have a public method to update the Text display and will take an int as a parameter. Finally, I’ll get a handle on the UIManager on the Player and call the method when the Player collects a coin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3X6sc65vsl22OCtGy8U_2A.gif" /></figure><p>In the UIManger script, I’ll create a serialized field for the text object and create the method to update the coin display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMz8_OaKm5wirpS1c-KgLQ.png" /></figure><p>Once I save and go back into Unity, I drag the Text object into the space on the UIManager asking for a Text object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*bSnkZHhTOmJGuPc9pu8kFQ.gif" /></figure><p>This completes the setup for the UIManager. Now I can move on to the Player script. First, I need to create a variable for the UIManager in the Player script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*rWrK4SlMm-G1znIGE-LLMw.png" /></figure><p>Next, I’ll use this variable to reference the UIManager script on the canvas object and null check it just to be safe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hC60IpGFeFPCUfPQpCkF2Q.png" /></figure><p>Now that I have a reference to the UIManager, I can call its method UpdateCoinDisplay() when the Player collects a coin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*BWI7r9XuS_V8QEc8pBWihw.png" /></figure><p>Now that everything is set, the coin display should update whenever a coin is collected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*VqPrkD9phknaWu1r5COa-g.gif" /></figure><p>And you can see the display updated when the first and second coins were collected by the Player just like it should.</p><p>That does it for setting up the collectibles for the game. I hope you found this interesting and informative. And as always, until next time, I wish you well on your own coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cbf47ab7d66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-collectibles-6cbf47ab7d66">2.5D Platformer: Collectibles</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2.5D Platformer: Character Controller, Part 2]]></title>
            <link>https://medium.com/geekculture/2-5d-platformer-character-controller-part-2-445e0acd7ae6?source=rss-517d1ca3e9af------2</link>
            <guid isPermaLink="false">https://medium.com/p/445e0acd7ae6</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Brian Branch]]></dc:creator>
            <pubDate>Fri, 20 Aug 2021 13:17:08 GMT</pubDate>
            <atom:updated>2021-08-27T16:59:48.087Z</atom:updated>
            <content:encoded><![CDATA[<p>In this second part of my article on creating a Character Controller for the 2.5D Platformer, I’ll be setting up the Gravity, Jumping, and Double-Jumping for the Player.</p><p>I’ve already created a variable for gravity and will set it to 1.0f for the moment and adjust it later if needed. To check for gravity, I’ll use a method from the Character Controller called isGrounded to see if the Player is standing on something. If it is true, I’ll do nothing for the moment, and if it is false, I’ll apply gravity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*IxdsZheCQFa7gvZbPE-u7A.png" /></figure><p>This now provides gravity so that the Player can fall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*nAaYa3qZiiJJh_p_kRu7jQ.gif" /></figure><p>The Player is falling slowly, but I’ll adjust this while adding in jumping as needed.</p><p>Now is the time to add jumping for the Player. I’m going to use the Space key to initiate the Player’s jump. First, I’ll check if the Space key has been pressed in the check for the isGrounded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*L4dIjj6ktTIPSqYJC2Umiw.png" /></figure><p>Now this will still present a problem, as you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*rA9k6piWpY2DpU50F51rGA.gif" /></figure><p>The Player is barely jumping at all. So what happens is that the velocity.y is getting reset to 0 for each frame. To alleviate this, I will create a float named yVelocity to cache the velocity I want to use for y.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*6Y6GpPPO_C0ZufttP6hI6A.png" /></figure><p>Now that I have that code in place, I’ll adjust the values for my gravity and jump height to make the movement a bit smoother.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*bifTPoJ-gl_Art3U7Hyyvg.png" /></figure><p>This gives a much nicer jump, although I think I may adjust the gravity a little bit more, so the Player doesn’t feel like they are being snatched down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*skpHWwyiIbe9-04Ux0OrZg.gif" /></figure><p>Now I’ll work on the double-jump functionality. First, I will create a bool to determine if the Player can double-jump, and I’ll name it _canDoubleJump, setting its initial value to false. This is because I only want them to double-jump once and only if the Player is not grounded. So when the player first jumps, _canDoubleJump will get set to true. Then if the player jumps again, it will be set back to false. The code for this is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*E5IxDctTeDc_3mBjhwAfdg.png" /></figure><p>Now the Player can jump and double-jump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*FSHk7XQ9YoPoUATFHE1X6A.gif" /></figure><p>That completes the setting up of the Character Controller for the 2.5D Platformer game. I hope you found this interesting, and as always, I wish you well on your own coding journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=445e0acd7ae6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/2-5d-platformer-character-controller-part-2-445e0acd7ae6">2.5D Platformer: Character Controller, Part 2</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>