<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>chan_2.log</title>
        <link>https://velog.io/</link>
        <description>Growing Game Dev</description>
        <lastBuildDate>Tue, 29 Jul 2025 01:37:36 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>chan_2.log</title>
            <url>https://velog.velcdn.com/images/chan_2/profile/f8d2edd4-1986-457d-90ad-8e33635fff18/social_profile.png</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. chan_2.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/chan_2" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Intro to C++ Part 1]]></title>
            <link>https://velog.io/@chan_2/Intro-to-C-Part-1</link>
            <guid>https://velog.io/@chan_2/Intro-to-C-Part-1</guid>
            <pubDate>Tue, 29 Jul 2025 01:37:36 GMT</pubDate>
            <description><![CDATA[<h2 id="intro">Intro</h2>
<ul>
<li>Every code must be written in <code>main()</code> function.<ul>
<li><code>main()</code> function is the entry point of the C++</li>
<li>Code in <code>main()</code> is the first to be <strong>executed</strong><blockquote>
<p>#include</p>
</blockquote>
</li>
</ul>
</li>
<li>Directive</li>
<li>Used to include <strong>head</strong> files.<ul>
<li>Head files contains declarations of functions and objects that program can use. </li>
</ul>
</li>
<li><code>#include &lt;iostream&gt;</code> includes the iostream header, which provides objects like <code>std::cout</code> for outputting text to the console. </li>
</ul>
<h2 id="variables">Variables</h2>
<ul>
<li>Hold data values.</li>
<li>Store, manipulate, display informations.</li>
<li>Initialize variable. <blockquote>
<p><code>Vaiable_type Variable_name = value;</code></p>
</blockquote>
</li>
<li><code>int</code> --&gt; represents whole numbers.</li>
<li><code>float</code> || <code>double</code> --&gt; represents real numbers.<ul>
<li><strong>float</strong> --&gt; decimal numbers // up to <strong>7 decimal digits</strong>.</li>
<li><strong>double</strong> --&gt; with more precisions // up to <strong>15 - 17 decimal digits</strong>.<blockquote>
<p><code>float variable_name = 99.99f;</code></p>
</blockquote>
</li>
</ul>
</li>
</ul>
<h3 id="string">String</h3>
<ul>
<li>To use string in C++, <code>include &lt;string&gt;</code> should be added on top of the code.</li>
<li>2 ways to implement*<ol>
<li>Adding <code>using namespace std;</code> after the <code>#include &lt;string&gt;</code></li>
<li><code>std::string cariable_name = &quot;This is a string.&quot;</code><blockquote>
<pre><code>#include &lt;string&gt;
using namespace std; // method 1
int main() {
string s1 = &quot;Hello.&quot;; // method 1
std::string s2 = &quot;Hello.&quot;; // method 2
return 0;
 }</code></pre></blockquote>
<pre><code></code></pre></li>
</ol>
</li>
</ul>
<h3 id="boolean">Boolean</h3>
<ul>
<li>Only 2 possible values, true || false<blockquote>
<pre><code>bool variable_true = true;
bool variable_false = false;</code></pre></blockquote>
</li>
<li>When printing boolean values using cout, true --&gt; 1 false --&gt; 0</li>
</ul>
<h3 id="char">Char</h3>
<ul>
<li>Represents single character</li>
<li>keyword = char<blockquote>
<p>char variable_name = &#39;h&#39;;</p>
</blockquote>
</li>
</ul>
<h3 id="constants--keyword-const">Constants // Keyword const</h3>
<ul>
<li>Variables that can&#39;t be changed once it&#39;s intialized.
<code>const int max_value = 100;</code><ul>
<li><code>max_value</code> can&#39;t be changed.</li>
</ul>
</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity  - Making simple 2D game part 1]]></title>
            <link>https://velog.io/@chan_2/Unity-Making-simple-2D-game</link>
            <guid>https://velog.io/@chan_2/Unity-Making-simple-2D-game</guid>
            <pubDate>Fri, 06 Sep 2024 02:54:54 GMT</pubDate>
            <description><![CDATA[<h3 id="starting">Starting</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/4c7b3f21-e149-4d6b-ad83-a1d2694231b4/image.png" alt=""></p>
<ul>
<li>I have simple movements for now, which is just moving, jumping.<blockquote>
<p>Goal is to implement wall jumping mechanic.</p>
</blockquote>
</li>
<li>I think it might take a while to achieve wall jumps because it&#39;s quite complicated.</li>
<li>This post is about me going through trials &amp; errors and record what I did.</li>
</ul>
<h3 id="how-to-wall-jump">How to Wall Jump</h3>
<h4 id="steps">Steps</h4>
<ol>
<li>Detect walls if the player is walking into the wall.</li>
<li>If the player is not on the ground and pressing towards the wall, the player starts sliding down the wall.</li>
<li>If the player is sliding down the wall, and the player is pressing jump button, force is applied on the opposite side of x value where the player is facing.</li>
</ol>
<h4 id="write-the-code">Write the code</h4>
<ul>
<li><p>I have to detect the wall first</p>
<pre><code class="language-c">public Transform wallCheck;
public LayerMask wallLayer;
  void Update()
  {
      if(WallCheck())
      {
          Debug.Log(&quot;Is wall&quot;);
      }
  }
  bool WallCheck()
  {
      return Physics2D.OverlapCircle(wallCheck.position, 0.2f, wallLayer);
  }

  private void OnDrawGizmos()
  {
      Gizmos.color = Color.red;
      Gizmos.DrawWireSphere(wallCheck.position, .2f);
  }</code></pre>
<p><img src="https://velog.velcdn.com/images/chan_2/post/6fef4ab4-1040-4ecf-b1e5-3924a9270b01/image.png" alt=""></p>
</li>
<li><p>I did <code>OnDrawGizmos()</code> to visualize the <code>Physics2D.OverlapCircle()</code></p>
</li>
<li><p>If the <code>OverlapCircle()</code> hits the wall layer, on the console it should say &quot;Is wall&quot;.
<img src="https://velog.velcdn.com/images/chan_2/post/a367a587-76a2-4e9b-bada-53c3e4755a19/image.png" alt=""></p>
<h4 id="wall-slide">Wall Slide</h4>
</li>
<li><p>If the player is not on the ground, and pressing against the wall, it should slide down the wall.</p>
<pre><code class="language-c">void WallSlide()
  {
      if (!isGround &amp;&amp; WallCheck() &amp;&amp; h != 0f)
      {
          isWallSliding = true;
          rigid.velocity = new Vector2(rigid.velocity.x, Mathf.Clamp(rigid.velocity.y, -wallSlidingSpeed, float.MaxValue));
      }
  }</code></pre>
<blockquote>
<p><code>Mathf.Clamp()</code> : Constrains a value within a specified range.</p>
</blockquote>
<pre><code class="language-c">Mathf.Clamp(float value to be clamped, float min, float max)</code></pre>
<p>The function returns</p>
</li>
<li><p>The original value if it&#39;s within the specified range.</p>
</li>
<li><p>The minimum value if the original value is less than the minimum.</p>
</li>
<li><p>The maximum value if the original value is greater than the maximum.</p>
</li>
<li><p><code>Mathf.Clamp()</code> is used to prevent accelerating while sliding down the wall.</p>
</li>
</ul>
<pre><code class="language-c">void WallSlide()
    {
        if (!isGround &amp;&amp; WallCheck() &amp;&amp; h != 0f)
        {
            isWallSliding = true;
            rigid.velocity = new Vector2(rigid.velocity.x, Mathf.Clamp(rigid.velocity.y, -wallSlidingSpeed, float.MaxValue));
        }
        else
        {
            isWallSliding = false;
        }
    }</code></pre>
<ul>
<li>Lastly, <code>else</code> is <code>isWallSliding = false;</code></li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/724116ac-2933-4e15-aa33-0e4ede775247/image.gif" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - How to Jump]]></title>
            <link>https://velog.io/@chan_2/Unity-How-to-Jump</link>
            <guid>https://velog.io/@chan_2/Unity-How-to-Jump</guid>
            <pubDate>Thu, 22 Aug 2024 19:18:52 GMT</pubDate>
            <description><![CDATA[<h3 id="how-to-jump">How to Jump</h3>
<blockquote>
<p>Just &quot;jumping&quot; is easier than I thought.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/7362833d-a336-4574-9da0-0ac49674a296/image.png" alt=""></p>
<ul>
<li>Make a variable for our jumpingPower, and use it to control our jump heights.</li>
</ul>
<pre><code class="language-c">if (Input.GetButtonDown(&quot;Jump&quot;))
        {
            rigid.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
        }</code></pre>
<ul>
<li>We&#39;re adding force to our rigidbody 2D, so wirte <code>rigid.Addforce</code>.</li>
<li>We&#39;re jumping, which means up. Therefore, do <code>Vector2.up</code> and multiply by the number of <code>jumpPower</code>.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/0f0037a2-5e3b-445e-ae0c-2912d8e233aa/image.gif" alt=""></p>
<ul>
<li>Now we are able to make our gameObject jump. However, you can jump infinitely.</li>
<li>This can be solved by checking if the player is touching the ground or not.</li>
</ul>
<h3 id="how-to-check-ground-with-boxcast">How to Check Ground with Boxcast</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/4b912f18-4576-41d0-af74-63a10572604e/image.png" alt=""></p>
<blockquote>
<p>Pseudo Code:
If the player is touching the ground and pressing jump button, the player can jump.
If the player is not touching the ground, the player can&#39;t jump.</p>
</blockquote>
<ul>
<li>Based on the pseudo code, we first need to  know if our player is on the ground or not.</li>
<li>We will use <code>Physics2D.Boxcast()</code> to check if the player is on the ground or not.</li>
</ul>
<blockquote>
<p><code>Physics.Boxcast()</code> creates a box-shaped volume and detects collision, which returns a boolean value.</p>
</blockquote>
<blockquote>
<p>Boxcast Parameters:</p>
</blockquote>
<pre><code class="language-c">Physics2D.Boxcast(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, int layerMask)</code></pre>
<h3 id="make-variables-for-the-ground-check">Make Variables for the Ground Check</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/e1ed2800-7d82-4875-ba2e-fe8d6f781690/image.png" alt=""></p>
<blockquote>
<p>We need to make variables that will go into the Boxcast parameters.</p>
</blockquote>
<ul>
<li>Vector2 to size our cast box.</li>
<li>float value to control the distance between the player&#39;s position and box cast.</li>
<li>Layermask to check which layer we are detecting for.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/01403fd4-e43b-46f7-9df2-37ea2459c737/image.png" alt=""></p>
<pre><code class="language-c">public bool IsGround()
    {
        if (Physics2D.BoxCast(transform.position, boxSize, 0, -transform.up, distance, groundLayer))
        {
            return true;
        }
        else
        {
            return false;
        }
    }</code></pre>
<ul>
<li><p>We will make a new bool called <code>IsGround()</code> so we can use it to check if the player is on the ground.</p>
</li>
<li><p>We can plug our variables into the Boxcast parameters.
I don&#39;t want any angles so I put 0 as a angle value.
I want to check what&#39;s under our player, so I did <code>-transform.up</code>.</p>
<blockquote>
<p>There&#39;s no <code>transform.left</code> or <code>transform.down</code> in transform components.</p>
</blockquote>
</li>
<li><p>Since it&#39;s a boolean, we&#39;ll return <code>true</code> if our Boxcast is detecting the ground, and return <code>false</code> if it&#39;s not detecting any ground.</p>
</li>
</ul>
<h3 id="visualize-the-boxcast">Visualize the Boxcast</h3>
<blockquote>
<p>Boxcast is not visible by default, so it&#39;s difficult to control it.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/381fd307-a00a-4cc9-905f-de8d37641169/image.png" alt=""></p>
<pre><code class="language-c">private void OnDrawGizmos()
    {
        Gizmos.DrawWireCube(transform.position - transform.up * distance, boxsize);
    }</code></pre>
<ul>
<li><p>We&#39;ll use <code>void OnDrawGizmos()</code>.</p>
<blockquote>
<p><code>void OnDrawGizmos()</code> is a tool that draws the visual represent for the gizmos. It&#39;s primarily used to debug or visual purposes.</p>
</blockquote>
</li>
<li><p>We can use <code>Gizmos.DrawWireCube</code> to visualize our Boxcast.</p>
<blockquote>
<p><code>Gizmos.DrawWireCube</code> draws wired cube to visualize the box.</p>
</blockquote>
</li>
<li><p>Use <code>(transform.position - transform.up * distance, boxsize);</code></p>
<blockquote>
<p>We want our center for the box to be same as Boxcast, which is why we did <code>transform.position - transform.up</code>. Then, we multiply it by the <code>distance</code> value to control the boxcast&#39;s y-axis location.</p>
</blockquote>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/5e5933f7-953d-4b2b-8e58-1e90ec397529/image.gif" alt=""></p>
<ul>
<li>Now we can visualize Boxcast and control it.</li>
</ul>
<h3 id="make-ground-layer-in-the-layer-component">Make Ground Layer in the Layer component</h3>
<blockquote>
<p>Now we can make a Layer called &quot;Ground&quot; to detect the ground.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/f2d4fdb5-db12-490f-867e-eabd5a5f96b4/image.png" alt=""></p>
<ul>
<li>Click Layer that&#39;s on the inspector window, and click Add Layer.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/27b69807-8e9f-43f0-a3d3-f1e5f355886b/image.png" alt=""></p>
<ul>
<li>Add the layer and name it &quot;Ground&quot;.</li>
<li>Make sure you select the layer after saving it.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/995bfbe3-b4c1-49a6-b19c-beec1a316efc/image.png" alt=""></p>
<ul>
<li>Then, go to the player&#39;s script and select Ground layer.</li>
</ul>
<h3 id="jump-only-once-using-ground-check">Jump only Once using Ground Check</h3>
<ul>
<li>Now, we&#39;ll make a <code>void Jump()</code> and call it in <code>Update()</code> to jump.</li>
</ul>
<pre><code class="language-c"> void Jump()
    {
        if (Input.GetButtonDown(&quot;Jump&quot;) &amp;&amp; IsGround())
        {
            rigid.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
        }

    }</code></pre>
<ul>
<li>If the player is pressing jump button and the player is on the ground, we&#39;ll add force to the player to go up.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/8a68d869-0b89-4b90-bdf1-31b10a7900ec/image.gif" alt=""></p>
<ul>
<li>Now we can only jump when we are on the ground.</li>
<li>Make sure you called the <code>void Jump()</code> in the <code>Update()</code> and selected the groundLayer in the player&#39;s script.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Setting the Tilemaps / Platform]]></title>
            <link>https://velog.io/@chan_2/Unity-Setting-the-Tilemaps-Platform</link>
            <guid>https://velog.io/@chan_2/Unity-Setting-the-Tilemaps-Platform</guid>
            <pubDate>Thu, 22 Aug 2024 16:31:46 GMT</pubDate>
            <description><![CDATA[<h3 id="movement-fixes">Movement Fixes</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/e9784832-5be9-4f46-b486-92d9df435581/image.png" alt=""></p>
<ul>
<li>If you follwed the last tile map tutorial, our tilemap already should have tilemap collider 2D.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/2d2b6a3d-bb08-40a1-9ff9-76ad1d2e01de/image.gif" alt=""></p>
<ul>
<li>If you start moving, you&#39;ll see our player gameObject moving up and down randomly.<blockquote>
<ul>
<li>This is because our tilemap collider is applied to each individual tiles.</li>
</ul>
</blockquote>
</li>
</ul>
<h3 id="solution">Solution</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/206aa2e0-d412-4968-9dc1-5707f4635d1c/image.png" alt=""></p>
<ul>
<li>To fix this, add Composite Collider 2D. <blockquote>
<p>Composite collider 2D merges all of the collider 2D, and in this case it will help merge all of the tiles into one big collider.</p>
</blockquote>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/00cbc7b8-0099-4ca8-94b0-807ed557aed7/image.png" alt=""></p>
<ul>
<li>Make sure you check the Used By Composite in Tilemap Collider 2D, and change body type to Static in RigidBody 2D component.</li>
</ul>
<blockquote>
<p><strong>Static</strong> body type do not move under physics simulation. It is an immovable object with infinite mass.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/75004664-79db-473b-9b75-d8bf253fab71/image.gif" alt=""></p>
<ul>
<li>Now it should be moving fine!</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Move the gameObject by Adding Force]]></title>
            <link>https://velog.io/@chan_2/Unity-Move-the-gameObject-by-Adding-Force</link>
            <guid>https://velog.io/@chan_2/Unity-Move-the-gameObject-by-Adding-Force</guid>
            <pubDate>Wed, 21 Aug 2024 17:10:56 GMT</pubDate>
            <description><![CDATA[<h2 id="add-force-to-the-rigidbody-2d-gameobject">Add Force to the RigidBody 2D GameObject</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/5b3a0af4-7cd6-4af0-8bd2-a14ad2d9aeb4/image.png" alt=""></p>
<pre><code class="language-c">Rigidbody2D rigid;

    float h;


      private void Awake()
    {
        rigid = GetComponent&lt;Rigidbody2D&gt;();
    }

    private void FixedUpdate()
    {
        h = Input.GetAxisRaw(&quot;Horizontal&quot;);

        rigid.AddForce(Vector2.right * h, ForceMode2D.Impulse);
    }</code></pre>
<ul>
<li>Moving the gameObject by adding force is little bit different from changing the velocity of the gameObject.</li>
</ul>
<pre><code class="language-c">rigid.AddForce(Vector2.right * h, ForceMode2D.Impulse);</code></pre>
<ul>
<li><p><code>AddForce</code> is a method that can apply force to rigidbody 2D.</p>
</li>
<li><p>We are not using any specified <code>Vector2</code> value, so we&#39;ll use <code>Vector2.right</code>
Reason why we&#39;re using <code>Vector2.right</code> is because <code>.right</code> is a positive number. If we did <code>.left</code> the gameObject will move opposite as to where we want it to move since it&#39;s negative number.</p>
</li>
<li><p>To make it move, we will multiply <code>h</code> value to <code>Vector2.right</code></p>
</li>
<li><p>We will use <code>ForceMode2D.Impulse</code> to move our player gameObject.</p>
</li>
</ul>
<blockquote>
<ul>
<li>When using <code>AddForce</code> method, there&#39;s <code>ForceMode2D.Impulse</code> and <code>ForceMode2D.Force</code>.</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li><code>ForceMode2D.Force</code> applies continuous force to the gameObject.</li>
</ul>
</blockquote>
<ul>
<li><code>ForceMode2D.Impulse</code> applies instant force to the gameObject.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/238fb26d-409c-4018-96a9-13b409abf38c/image.png" alt=""></p>
<ul>
<li>Now we are able to make out gameObject move, but it&#39;s moving inconsistently and really fast.</li>
</ul>
<blockquote>
<ul>
<li>This is because we wrote the code in <code>FixedUpdate()</code></li>
</ul>
</blockquote>
<ul>
<li>We are applying instant force to the rigidbody 2D for every 50 frames, which is why it&#39;s accelerating.</li>
</ul>
<h3 id="setting-the-max-speed-limit">Setting the Max Speed Limit</h3>
<blockquote>
<p>To stop this from happening, we can set <strong>MaxSpeed</strong> value.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/e57e793a-e1fb-42ff-9fe4-bcbad583724e/image.png" alt=""></p>
<ul>
<li>It&#39;s helpful to pseudo code before writing the actual code. </li>
</ul>
<pre><code class="language-c">        //if rigid&#39;s positive x velocity is bigger than the maxSpeed
        //then rigid&#39;s positive x velocity is maxSpeed
        //if rigid&#39;s negative x velocity is bigger than the maxSpeed * -1
        //then rigid&#39;s negative x velocity is maxSpeed * -1</code></pre>
<ul>
<li>After doing so, write it in code terms. In this case, </li>
</ul>
<pre><code class="language-c">if(rigid.velocity.x &gt; maxSpeed)
{
    rigid.velocity = new Vector2(maxSpeed, rigid.velocity.y);
}
else if(rigid.velocity.x &lt; maxSpeed * (-1))
{
    rigid.velocity = new Vector2(maxSpeed * (-1), rigid.velocity.y);
}
</code></pre>
<p><img src="https://velog.velcdn.com/images/chan_2/post/397da85b-0455-4503-bc2a-a587cfe27996/image.png" alt=""></p>
<p>Now we should be able to move our player gameObject.</p>
<h2 id="control-gameobject-from-sliding">Control GameObject from sliding</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/0a3c01a7-d8b0-415b-afcd-f5a2af4c3fb2/image.gif" alt=""></p>
<ul>
<li>One Problem is our charcter starts sliding after the player stoped moving. This can be solved by assigning a <code>new Vector2</code> value when the player stops pressing onto the keyboard.<blockquote>
<p>Pseudo Code: </p>
</blockquote>
  //if the player stops pressing the keyboard,
  //then rigid will assign new x velocity value to decrease speed.</li>
</ul>
<p>Apply to the code:</p>
<pre><code class="language-c">    private void Update()
    {
        if (Input.GetButtonUp(&quot;Horizontal&quot;))
        {
            rigid.velocity = new Vector2(rigid.velocity.normalized.x, rigid.velocity.y);
        }
    }</code></pre>
<ul>
<li><p>We will use <code>Update()</code> since we want to consistently decrease the gameObject&#39;s velocity.</p>
</li>
<li><p><code>normalized</code> converts the <code>Vector</code> to a unit vector, meaning it will have magnitude to 1 while maintaining the original direction.</p>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/f1ce55c5-dd18-4352-a9a7-c5a5a6176513/image.png" alt=""></p>
<ul>
<li>It should look like this.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/88eb3190-416d-43af-be77-9348c2ee8e8c/image.gif" alt=""></p>
<h3 id="next">Next:</h3>
<p>Setting the tilesmap(platform) so the gameObject doens&#39;t collide with individual tilemap.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Move the Player Using Scripts Part 2]]></title>
            <link>https://velog.io/@chan_2/Unity-Move-the-Player-Using-Scripts-Part-2</link>
            <guid>https://velog.io/@chan_2/Unity-Move-the-Player-Using-Scripts-Part-2</guid>
            <pubDate>Wed, 21 Aug 2024 05:38:14 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/chan_2/post/4d556959-5679-455c-973b-3bdded5c54cc/image.png" alt=""></p>
<h3 id="get-the-gameobjects-axis-value">Get the gameObject&#39;s axis value</h3>
<blockquote>
<p>To move the character, you have to apply force to them by either <strong>changing the gameobject&#39;s velocity</strong> or by <strong>applying force</strong> to them.</p>
</blockquote>
<ul>
<li><p>After getting the component from Awake(), you can manipulate it in the FixedUpdate() to move it.</p>
<pre><code class="language-c">    Rigidbody2D rigid;

    float h;
    public float walkSpeed;

      private void Awake()
    {
        rigid = GetComponent&lt;Rigidbody2D&gt;();
    }

    private void FixedUpdate()
    {
        h = Input.GetAxisRaw(&quot;Horizontal&quot;);

        rigid.velocity = new Vector2(h * walkSpeed, rigid.velocity.y);
    }</code></pre>
</li>
<li><p>In the FixedUpdate, we need a variable to store our <code>Input.GetAxisRaw</code> code.</p>
</li>
</ul>
<blockquote>
<p><code>Input.GetAxisRaw</code> gets the value of virtue axis. For this case, -1 or 1 for x-axis.</p>
</blockquote>
<ul>
<li>To store our <code>Input.GetAxisRaw</code>, we declare <code>h</code> as our float value before <code>Awake()</code> and set <code>h = Input.GetAxisRaw(&quot;Horizontal&quot;)</code></li>
</ul>
<blockquote>
<ul>
<li><code>&quot;Horizontal&quot;</code> is unity&#39;s built in system which captures the gameObjects horizontal movements. By default it is set to <code>left arrow</code> &amp; <code>right arrow</code> and <code>a</code> &amp; <code>d</code> keys on the keyboard.</li>
<li>This can be found on Edit -&gt; Project Settings -&gt; Input Management.</li>
</ul>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/5c70cc97-889f-4e44-9707-18b2f1602c54/image.png" alt=""></p>
<p><img src="https://velog.velcdn.com/images/chan_2/post/acc13936-1abf-49b6-a09f-8f47aaf00ac5/image.png" alt=""></p>
<ul>
<li>As you can see there&#39;s a lot of other inputs that we can use.</li>
<li>If you want to change the number of inputs, you can change the size number.</li>
</ul>
<h3 id="apply-the-velocity-to-the-rigidbody-2d">Apply the velocity to the Rigidbody 2D</h3>
<pre><code class="language-c">  Rigidbody2D rigid;

      float h;
      public float walkSpeed;

        private void Awake()
      {
          rigid = GetComponent&lt;Rigidbody2D&gt;();
      }

      private void FixedUpdate()
      {
          h = Input.GetAxisRaw(&quot;Horizontal&quot;);

          rigid.velocity = new Vector2(h * walkSpeed, rigid.velocity.y);
      }
  }</code></pre>
<ul>
<li>Now we need to write a code to <strong>change the velocity</strong> of the gameObject.</li>
</ul>
<pre><code class="language-c">  rigid.velocity = new Vector2(h * walkSpeed, rigid.velocity.y);</code></pre>
<ul>
<li><p>We are going to tap in to our rigidbody 2D&#39;s velocity so write <code>rigid.velocity</code> </p>
</li>
<li><p>Since we want to specify our Vector2, we will use <code>new Vector2</code></p>
</li>
</ul>
<blockquote>
<p><code>new Vector2</code> is used when we need to create a new Vector2 with <strong>specific x and y components</strong>.</p>
</blockquote>
<ul>
<li><p>For our x-axis value, we will use <code>h</code> value which is -1 or 1, since we want to move from left to right.</p>
</li>
<li><p>For our y-axis value, we <strong>don&#39;t want to move vertically</strong> when we move horizontally. Therefore, we will leave it as it is. This can be done by <code>rigid.velocity.y</code>.</p>
</li>
</ul>
<pre><code class="language-c">rigid.velocity = new Vector2(h, rigid.velocity.y);</code></pre>
<ul>
<li><p>Our gameObject can move with this code, but it will only move at -1 or 1 speed becuase of our <code>h</code> value which is our <code>Input.GetAxisRaw(&quot;Horizontal&quot;)</code> value.</p>
</li>
<li><p>We can solve this problem by making another variable called <code>public float walkSpeed;</code> before <code>Awake()</code>.</p>
</li>
</ul>
<blockquote>
<ul>
<li>By making <code>public float walkSpeed;</code> public, we can access it from the gameObject&#39;s script section from the inspector window.</li>
</ul>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/7e6a4e34-308b-4188-b425-4cc052fe6f1b/image.png" alt=""></p>
<ul>
<li>Now, we can multiply the <code>walkSpeed</code> to our h value to make it go faster.</li>
</ul>
<pre><code class="language-c">rigid.velocity = new Vector2(h * walkSpeed, rigid.velocity.y);</code></pre>
<blockquote>
<p><strong>Make sure to save the script before playing the scene!</strong></p>
</blockquote>
<h3 id="constraints">Constraints</h3>
<p><img src="https://velog.velcdn.com/images/chan_2/post/f4557c41-f819-4acc-9dca-ebb228e2e770/image.png" alt=""></p>
<ul>
<li>When you start moving, the gameObject might rotate.</li>
</ul>
<blockquote>
<ul>
<li>This can be fixed by <strong>freezing the gameObject&#39;s z-axis</strong> in constraints for Rigidbody 2D component.</li>
</ul>
</blockquote>
<h3 id="next">Next</h3>
<p>Apply force to the gameObject to move.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Move the Player Using Scripts Part 1]]></title>
            <link>https://velog.io/@chan_2/Unity-Move-the-Player-Using-Scripts-Part-1</link>
            <guid>https://velog.io/@chan_2/Unity-Move-the-Player-Using-Scripts-Part-1</guid>
            <pubDate>Tue, 20 Aug 2024 02:12:00 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/chan_2/post/13a0db44-2094-4475-afc1-6bb4558861c1/image.png" alt=""></p>
<h3 id="awake">Awake()</h3>
<pre><code>public class PlayerMove : MonoBehaviour
{
    Rigidbody2D rigid;

      private void Awake()
    {
        rigid = GetComponent&lt;Rigidbody2D&gt;();
    }


}</code></pre><ul>
<li><p>Get the gameObject&#39;s Rigidbody2D componenet and set name for it. For this case it&#39;s rigid, but you can call it however you want like rb or body2D.</p>
</li>
<li><p>In the Awake(), use GetComponent&lt;&gt; to access and manipulate the component. We&#39;re going to manipulate Rigidbody2D here so I did </p>
<pre><code>rigid = GetComponenet&lt;Rigidbody2D&gt;();</code></pre><blockquote>
<p>Make sure to put () after the &lt;&gt; to complete the code. </p>
</blockquote>
</li>
</ul>
<p>Now we can move on to actually writing the code so our player gameobject can move.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Adding Basic components to the GameObject]]></title>
            <link>https://velog.io/@chan_2/Unity-Adding-Basic-components-to-the-GameObject</link>
            <guid>https://velog.io/@chan_2/Unity-Adding-Basic-components-to-the-GameObject</guid>
            <pubDate>Fri, 16 Aug 2024 17:04:40 GMT</pubDate>
            <description><![CDATA[<h2 id="adding-rigidbody-2d">Adding RigidBody 2D</h2>
<blockquote>
<p>RigidBody 2D adds 2D physics(falling for example) to the gameObject.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/71e7afdf-5ca1-462a-be71-4373fc39594b/image.png" alt=""></p>
<ul>
<li>Select AddComponent and type RigidBody 2D</li>
<li>Adding RigidBody 2D will enable the gameObject to interact with eachother.</li>
</ul>
<h2 id="adding-collider-2d">Adding Collider 2D</h2>
<blockquote>
<p>Collider 2D defines the physical shape of a 2D GameObject for the purposes of physics interactions.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/7974de79-4f1a-4278-9e24-ca4b44687d44/image.png" alt=""></p>
<ul>
<li>Allows the gameObject to collide with other gameObjects and trigger events. </li>
</ul>
<h2 id="adding-scripts-1">Adding Scripts 1</h2>
<blockquote>
<p>By adding a script to the game object, you can define how the gameObject behaves.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/f12faf9d-b1a8-462d-96a1-8768c778431f/image.png" alt=""></p>
<ul>
<li>Click on Add Component and type script. Then, name the script and save it.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/9894ca70-af3b-4b22-a8a6-9230b33f9999/image.png" alt=""></p>
<ul>
<li>Once you save the script, wait for few seconds and the script should be in your Assets folder.</li>
</ul>
<h2 id="adding-scripts-2">Adding Scripts 2</h2>
<blockquote>
<p>I prefer to make a script folder first, and then make a script.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/e8c8e52b-a12f-4bea-9e43-d1f5c6c2ed66/image.png" alt=""></p>
<ul>
<li>Create a new folder under Assests folder.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/5de99c94-40ee-407f-9f27-fe5498194a04/image.png" alt=""></p>
<ul>
<li>Name the folder and create C# script in it.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/81cff66f-739d-45dc-8ed6-91eb724dda6a/image.png" alt=""></p>
<ul>
<li>Make sure to drag and drop the script onto the add component section of the gameObject to apply the script after.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity -Add Tilemaps(Platform) ]]></title>
            <link>https://velog.io/@chan_2/Unity-Add-TilemapsPlatform</link>
            <guid>https://velog.io/@chan_2/Unity-Add-TilemapsPlatform</guid>
            <pubDate>Thu, 15 Aug 2024 20:55:16 GMT</pubDate>
            <description><![CDATA[<h2 id="add-tilemaps-to-the-project">Add Tilemaps to the project</h2>
<blockquote>
<p>Tilemap is a tool used for storing tile assets and  build level designs.</p>
</blockquote>
<p><img src="https://velog.velcdn.com/images/chan_2/post/929c0033-902e-4548-9435-6489e05453c1/image.png" alt=""></p>
<ul>
<li>To make a tilemap, right click on the hierarchy, go to 2D object -&gt; Tilemap -&gt; Rectangular</li>
<li>Try to play around with Tilemap section and see what each one of them does. But in this case, I&#39;ll use rectangular.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/23182238-861f-46b1-9612-4049fdcf9520/image.png" alt=""></p>
<ul>
<li><p>After creating a tilemap heirarchy, go to tile pallet window and create new pallet.
<img src="https://velog.velcdn.com/images/chan_2/post/c7042fab-4faa-47d2-86da-1a091f2063e8/image.png" alt=""></p>
</li>
<li><p>Once you create a new pallet, save it.</p>
</li>
<li><p>I create new folder &quot;Tiles&quot; and save the pallet in there to manage it easily. </p>
</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/7ed59c5b-a92b-4729-8843-6d4d67dd6b2a/image.png" alt=""></p>
<ul>
<li>After saving the tile pallet in the Tiles file, create a new 2D sprite by following the steps above picture.</li>
<li>Then, drag the 2D sprite into the tile pallet.</li>
</ul>
<p><img src="https://velog.velcdn.com/images/chan_2/post/6e039fe4-58a0-47f9-8f73-24585f7385f3/image.png" alt=""></p>
<ul>
<li>Lastly, add Tilemap Collider 2D componenet in the inspector window like above. This will add collider to the tilemap so the player can stay above it.</li>
<li>Make sure the player has collider and rigidBody 2D applied!</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity - Basic 2D sprite contorls]]></title>
            <link>https://velog.io/@chan_2/Unity-Basic-2D-sprite-contorls</link>
            <guid>https://velog.io/@chan_2/Unity-Basic-2D-sprite-contorls</guid>
            <pubDate>Thu, 15 Aug 2024 20:20:34 GMT</pubDate>
            <description><![CDATA[<h2 id="unity-starting-screen">Unity starting screen</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/5e952dac-0ba4-4dfd-95c6-a44c87449e66/image.png" alt="">
Before starting, I customized my unity starting screen, so I can see the game view and scene window at the same time. For the Bottom half I put my hierarchy, project, and tile pallet window for easy access. I found out this layout works the best for me, so try moving around the windows and see what layout works the best for you.</p>
<h2 id="how-to-create-2d-gameobjects">How to create 2D gameObjects</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/6283c34a-8179-4861-a4bf-b64459cff796/image.png" alt=""></p>
<ul>
<li><p>To create 2D sprites, right-click on the heirarchy window. </p>
</li>
<li><p>Go to 2D Object -&gt; Sprites.
I generally use Triangle or squre sprites before applying the actual animated sprites.</p>
<h2 id="how-to-control-gameobjects">How to Control GameObjects</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/9719f4d4-3f34-49b8-b093-e01d8f1135d1/image.png" alt=""></p>
<h3 id="move-around-the-scene">Move around the scene</h3>
</li>
<li><p>Short cut for this action is &quot;q&quot; on the keyboard.</p>
</li>
<li><p>It&#39;s pretty straight forward. You can move around the scene.</p>
<h2 id="move-the-2d-gameobject">Move the 2D GameObject</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/9ca84dae-6d36-4a41-9998-0cf1624bf743/image.png" alt=""></p>
</li>
<li><p>Short cut for this action is &quot;w&quot; on the keyboard.</p>
</li>
<li><p>Pressing on the blue rectangle in the middle, you can move around the 2D gameObject freely.</p>
</li>
<li><p>Pressing on the green arrow, which is y-axis, you can only move the 2D gameObject in the y-axis.</p>
</li>
<li><p>Pressing on the red arrow, which is x-axis, you can only move the 2D gameObject in the x-axis.</p>
<h2 id="rotate-the-2d-gameobject">Rotate the 2D GameObject</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/4020981f-6691-4585-9fde-1337eca2b412/image.png" alt=""></p>
</li>
<li><p>Short cut for this action is &quot;e&quot; on the keyboard.</p>
</li>
<li><p>You can rotate the sprite by pressing on the blue line.</p>
</li>
<li><p>I suggest to play around with it and see how it works.</p>
<h2 id="stretch-the-2d-gameobject">Stretch the 2D GameObject</h2>
<p><img src="https://velog.velcdn.com/images/chan_2/post/e2826bf2-6845-447b-8935-0d2aed3b1edd/image.png" alt=""></p>
</li>
</ul>
<ul>
<li>Short cut for this action is &quot;r&quot; on the keyboard.</li>
<li>You can stretch the sprite along the y-axis or x-axis.</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Unity Flow]]></title>
            <link>https://velog.io/@chan_2/Unity-Flow</link>
            <guid>https://velog.io/@chan_2/Unity-Flow</guid>
            <pubDate>Wed, 14 Aug 2024 21:22:10 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/chan_2/post/8bb8abbd-b997-468c-8006-fdfcf73bd85b/image.webp" alt=""></p>
<blockquote>
<ol>
<li>void Awake()</li>
</ol>
</blockquote>
<ul>
<li>Initializes variables and set up game states before starting the game.</li>
</ul>
<blockquote>
<p>void OnEnable()</p>
</blockquote>
<ul>
<li>Executes when the gameObject is enabled.</li>
</ul>
<blockquote>
<p>void start()</p>
</blockquote>
<ul>
<li>Happens right before the Update() part of the code</li>
</ul>
<blockquote>
<p>void FixedUpdate()</p>
</blockquote>
<ul>
<li>Operates in consistent &quot;fixed&quot; time interval</li>
<li>Uses about 50fps</li>
<li>Suitable for physics calculations, ex) applying forces to rigid body.</li>
</ul>
<blockquote>
<p>void Update()</p>
</blockquote>
<ul>
<li>Called &quot;once per frame&quot; </li>
<li>implement game logic || behaviors that needs to be updated frequently. Ex) Jump</li>
<li>Main game logic is coded in Update() such as checking for users input, updating non-obj position</li>
<li>interval b/w Update() might vary due to the environment setting. Ex) pc specs</li>
<li>deals with user input, moving obj, or update animations etc.</li>
<li>important to account for time-based operations b/w frames. Generally sovled but using Time.deltaTime method.</li>
</ul>
<blockquote>
<p>void LateUpdate()</p>
</blockquote>
<ul>
<li>works silmilar with Update(), but executed after Update() is finished. </li>
<li>Ex) adjusting the camer position || animations after some objects have been &quot;updated&quot;</li>
</ul>
<blockquote>
<p>void OnDisable()</p>
</blockquote>
<ul>
<li>executes when the gameObject is disabled.</li>
</ul>
<blockquote>
<p>void OnDestroy()</p>
</blockquote>
<ul>
<li>executes when the gameObject gets destroyed</li>
</ul>
]]></description>
        </item>
    </channel>
</rss>