<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# &#8211; INCD021</title>
	<atom:link href="https://incd021.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>https://incd021.com</link>
	<description>Programming, thoughts, life  and art.</description>
	<lastBuildDate>Fri, 07 Jun 2013 15:32:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Player movement script for the 3&#215;3 POC</title>
		<link>https://incd021.com/2013/06/07/player-movement-script-for-the-3x3-poc/</link>
					<comments>https://incd021.com/2013/06/07/player-movement-script-for-the-3x3-poc/#comments</comments>
		
		<dc:creator><![CDATA[INC $D021]]></dc:creator>
		<pubDate>Fri, 07 Jun 2013 15:32:58 +0000</pubDate>
				<category><![CDATA[3x3]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[POC]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Unity Script]]></category>
		<category><![CDATA[Unity3D]]></category>
		<guid isPermaLink="false">http://incd021.com/?p=277</guid>

					<description><![CDATA[I just wanted to show how I chose to do the player control script. After playing the game some more, I&#8217;ve decided that the game isn&#8217;t going to work on....]]></description>
										<content:encoded><![CDATA[<p>I just wanted to show how I chose to do the player control script. After playing the game some more, I&#8217;ve decided that the game isn&#8217;t going to work on the mobile devises. The swipe to move the player would be very counter intuitive after level 8.</p>
<p>For the movement script, I wanted the player to move in a continuous motion and not in discreet jumps. The player should also be able to keep moving in one direction holding down a direction button.</p>
<p>To keep track of what the player is doing, I first made an enum with the possible motion states.<br />
I guess the enums are self explanatory <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<pre class="brush: actionscript3; gutter: true">enum Moving
{
    NO,
    UP,
    DOWN,
    LEFT,
    RIGHT
};</pre>
<p>Now the the logic. If the player isn&#8217;t moving, check for player input.</p>
<pre class="brush: actionscript3; gutter: true">
        if (direction == Moving.NO)
        {
            if (Input.GetKey(KeyCode.A))
            {
                direction = Moving.LEFT;
            }
            if (Input.GetKey(KeyCode.D))
            {
                direction = Moving.RIGHT;
            }
            if (Input.GetKey(KeyCode.W))
            {
                direction = Moving.UP;
            }
            if (Input.GetKey(KeyCode.S))
            {
                direction = Moving.DOWN;
            }
        }</pre>
<p>Now if the player is moving, the enum will be holding the direction of motion and we can move the player.</p>
<pre class="brush: actionscript3; gutter: true">            switch (direction)
            {
                case Moving.UP:
                    if (moveLeft &gt; 0f)
                    {
                        Vector3 v3 = transform.position;
                        v3.y += movementSpeed;
                        moveLeft -= +movementSpeed;
                        if (v3.y &gt; 1f)
                        {
                            v3.y = 1f;
                            moveLeft = 1.0f;
                            direction = Moving.NO;
                        }
                        transform.position = v3;
                    }
                    else
                    {
                        moveLeft = 1.0f;
                        direction = Moving.NO;
                    }
                    break;
                case Moving.DOWN:
                    if (moveLeft &gt; 0f)
                    {
                        Vector3 v3 = transform.position;
                        v3.y -= movementSpeed;
                        moveLeft -= +movementSpeed;
                        if (v3.y &lt; -1f)
                        {
                            v3.y = -1f;
                            moveLeft = 1.0f;
                            direction = Moving.NO;
                        }
                        transform.position = v3;
                    }
                    else
                    {
                        moveLeft = 1.0f;
                        direction = Moving.NO;
                    }
                    break;
                case Moving.LEFT:
                    if (moveLeft &gt; 0f)
                    {
                        Vector3 v3 = transform.position;
                        v3.x -= movementSpeed;
                        moveLeft -= +movementSpeed;
                        if (v3.x &lt; -1f)
                        {
                            v3.x = -1f;
                            moveLeft = 1.0f;
                            direction = Moving.NO;
                        } transform.position = v3;
                    }

                    else
                    {
                        moveLeft = 1.0f;
                        direction = Moving.NO;
                    }
                    break;
                case Moving.RIGHT:
                    if (moveLeft &gt; 0f)
                    {
                        Vector3 v3 = transform.position;
                        v3.x += movementSpeed;
                        moveLeft -= +movementSpeed;
                        if (v3.x &gt; 1f)
                        {
                            v3.x = 1f;
                            moveLeft = 1.0f;
                            direction = Moving.NO;
                        }
                        transform.position = v3;
                    }
                    else
                    {
                        moveLeft = 1.0f;
                        direction = Moving.NO;
                    }
                    break;
                default:
                    break;
            }</pre>
<p>That&#8217;s it, not pretty but it works. If I have the time, I would like to make the motion even more fluent. The state change if you keep a key down makes the player give a little jump/jitter as the state goes through NO state before returning to a moving state. But for now it gets the job done <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>All feedback is welcome, I can&#8217;t change if I don&#8217;t know what to change. <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>&#8211; Henning</p>
]]></content:encoded>
					
					<wfw:commentRss>https://incd021.com/2013/06/07/player-movement-script-for-the-3x3-poc/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Page Caching using Disk: Enhanced 

Served from: incd021.com @ 2025-05-18 03:34:07 by W3 Total Cache
-->