<?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>Variance Theory &#187; Unity3D</title>
	<atom:link href="http://variancetheory.com/tag/unity3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://variancetheory.com</link>
	<description>The work of Ben Throop - Artist, Designer, and Developer</description>
	<lastBuildDate>Mon, 29 Mar 2010 02:34:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Digging into Unity3D &#8211; Part 2</title>
		<link>http://variancetheory.com/digging-into-unity3d-part-2/</link>
		<comments>http://variancetheory.com/digging-into-unity3d-part-2/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 15:50:04 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://variancetheory.com/?p=398</guid>
		<description><![CDATA[So yesterday I spent several hours with Unity and discovered some cool stuff.
First I put together something like a Hello World app&#8230; certainly not a game, but what I&#8217;d consider the bare minimum that&#8217;s still &#8220;something&#8221;. I wouldn&#8217;t quite call this a tutorial since I only started myself, but if you are at Step Zero [...]]]></description>
			<content:encoded><![CDATA[<p>So yesterday I spent several hours with Unity and discovered some cool stuff.</p>
<p>First I put together something like a Hello World app&#8230; certainly not a game, but what I&#8217;d consider the bare minimum that&#8217;s still &#8220;something&#8221;. I wouldn&#8217;t quite call this a tutorial since I only started myself, but if you are at Step Zero with Unity you may find it useful in understanding the basics.  At the end, we&#8217;ll have a terrain, a sky, and a controllable player. There will be a camera tied to the capsule in first person. Then once we&#8217;ve done that, we&#8217;ll switch it to third person. Most of these instructions were found in the comments of the scripts that come with Unity&#8230; which was the first revelation that I had about how to learn. Online tutorials are good, but the example stuff is commented very well and explains a lot.</p>
<p>So, here&#8217;s what I did.</p>
<ol>
<li>Make a new project and use the standard Unity assets.</li>
<li>Let&#8217;s rearrange our windows a bit so we can see the game and scene views at the same time. Drag the Scene tab down to the bottom of the Scene viewport. It should expand to fill the bottom half. Release it and you&#8217;ll have the Game view on top and the Scene view on the bottom. Very handy.</li>
<li>Choose Menu-&gt;Terrain-&gt;Create Terrain</li>
<li>Choose Menu-&gt;GameObject-&gt;Create Other-&gt;Directional Light</li>
<li>With the directional light selected, hit &#8220;E&#8221; to enter rotate mode.</li>
<li>Grab the red circle on the rotation maniuplator and drag it until it&#8217;s about 45 degrees down (+45 degrees if you&#8217;re looking at the transform in the Inspector to the right.) Notice the terrain lighting up.</li>
<li>Choose Main Camera in the Hierarchy Panel</li>
<li>Choose Menu-&gt;Component-&gt;Rendering-&gt;Skybox &#8211; This creates a spot for us to drop a piece of Skybox art onto the camera. Once we do, it knows exactly how to act.</li>
<li>In the Project Panel, there are some basic starter assets. Get to Standard Assets-&gt;Skyboxes and drag Blue Sky over to Inspector panel with the Main Camera still selected. Drop it on the spot that says Custom Skybox.  The sky should show up in the Game view, but not the Scene view.</li>
<li>Now we&#8217;ve got land and a sky. Let&#8217;s add a player. Choose Menu-&gt;GameObject-&gt;Create Other-&gt;Capsule.</li>
<li>Click in the Scene view and then make sure Capsule is still selected. Hit &#8220;F&#8221; to focus on the capsule. Pretty cool how it smoothly zooms for you so you can get some idea of relational space.</li>
<li>The capsule is half in the terrain, so let&#8217;s raise it up. Hit &#8220;W&#8221; to go into Move mode and drag the Green arrow up a bit. Hit F again to refocus.</li>
<li>Now here&#8217;s interesting part. In Project, open up the Camera Scripts folder. Double click on MouseLook. Notice in the comments that there&#8217;s instructions on how to make the Capsule into an FPS style character. They read:</li>
</ol>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p398code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p3982"><td class="code" id="p398code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">UnityEngine</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// MouseLook rotates the transform based on the mouse delta.</span>
<span style="color: #008080; font-style: italic;">/// Minimum and Maximum values can be used to constrain the possible rotation</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// To make an FPS style character:</span>
<span style="color: #008080; font-style: italic;">/// - Create a capsule.</span>
<span style="color: #008080; font-style: italic;">/// - Add a rigid body to the capsule</span>
<span style="color: #008080; font-style: italic;">/// - Add the MouseLook script to the capsule.</span>
<span style="color: #008080; font-style: italic;">///   -&amp;gt; Set the mouse look to use LookX. (You want to only turn character but not tilt it)</span>
<span style="color: #008080; font-style: italic;">/// - Add FPSWalker script to the capsule</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.</span>
<span style="color: #008080; font-style: italic;">/// - Add a MouseLook script to the camera.</span>
<span style="color: #008080; font-style: italic;">///   -&amp;gt; Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)</span>
<span style="color: #000000;">&#91;</span>AddComponentMenu<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Camera-Control/Mouse Look&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MouseLook <span style="color: #008000;">:</span> MonoBehaviour <span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> RotationAxes <span style="color: #000000;">&#123;</span> MouseXAndY <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, MouseX <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, MouseY <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">public</span> RotationAxes axes <span style="color: #008000;">=</span> RotationAxes.<span style="color: #0000FF;">MouseXAndY</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> sensitivityX <span style="color: #008000;">=</span> 15F<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> sensitivityY <span style="color: #008000;">=</span> 15F<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> minimumX <span style="color: #008000;">=</span> <span style="color: #008000;">-</span>360F<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> maximumX <span style="color: #008000;">=</span> 360F<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> minimumY <span style="color: #008000;">=</span> <span style="color: #008000;">-</span>60F<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> maximumY <span style="color: #008000;">=</span> 60F<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #FF0000;">float</span> rotationX <span style="color: #008000;">=</span> 0F<span style="color: #008000;">;</span>
	<span style="color: #FF0000;">float</span> rotationY <span style="color: #008000;">=</span> 0F<span style="color: #008000;">;</span>
&nbsp;
	Quaternion originalRotation<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">void</span> Update <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>axes <span style="color: #008000;">==</span> RotationAxes.<span style="color: #0000FF;">MouseXAndY</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Read the mouse input axis</span>
			rotationX <span style="color: #008000;">+=</span> Input.<span style="color: #0000FF;">GetAxis</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Mouse X&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> sensitivityX<span style="color: #008000;">;</span>
			rotationY <span style="color: #008000;">+=</span> Input.<span style="color: #0000FF;">GetAxis</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Mouse Y&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> sensitivityY<span style="color: #008000;">;</span>
&nbsp;
			rotationX <span style="color: #008000;">=</span> ClampAngle <span style="color: #000000;">&#40;</span>rotationX, minimumX, maximumX<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			rotationY <span style="color: #008000;">=</span> ClampAngle <span style="color: #000000;">&#40;</span>rotationY, minimumY, maximumY<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Quaternion xQuaternion <span style="color: #008000;">=</span> Quaternion.<span style="color: #0000FF;">AngleAxis</span> <span style="color: #000000;">&#40;</span>rotationX, Vector3.<span style="color: #0000FF;">up</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			Quaternion yQuaternion <span style="color: #008000;">=</span> Quaternion.<span style="color: #0000FF;">AngleAxis</span> <span style="color: #000000;">&#40;</span>rotationY, Vector3.<span style="color: #0000FF;">left</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			transform.<span style="color: #0000FF;">localRotation</span> <span style="color: #008000;">=</span> originalRotation <span style="color: #008000;">*</span> xQuaternion <span style="color: #008000;">*</span> yQuaternion<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>axes <span style="color: #008000;">==</span> RotationAxes.<span style="color: #0000FF;">MouseX</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			rotationX <span style="color: #008000;">+=</span> Input.<span style="color: #0000FF;">GetAxis</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Mouse X&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> sensitivityX<span style="color: #008000;">;</span>
			rotationX <span style="color: #008000;">=</span> ClampAngle <span style="color: #000000;">&#40;</span>rotationX, minimumX, maximumX<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Quaternion xQuaternion <span style="color: #008000;">=</span> Quaternion.<span style="color: #0000FF;">AngleAxis</span> <span style="color: #000000;">&#40;</span>rotationX, Vector3.<span style="color: #0000FF;">up</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			transform.<span style="color: #0000FF;">localRotation</span> <span style="color: #008000;">=</span> originalRotation <span style="color: #008000;">*</span> xQuaternion<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			rotationY <span style="color: #008000;">+=</span> Input.<span style="color: #0000FF;">GetAxis</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Mouse Y&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> sensitivityY<span style="color: #008000;">;</span>
			rotationY <span style="color: #008000;">=</span> ClampAngle <span style="color: #000000;">&#40;</span>rotationY, minimumY, maximumY<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			Quaternion yQuaternion <span style="color: #008000;">=</span> Quaternion.<span style="color: #0000FF;">AngleAxis</span> <span style="color: #000000;">&#40;</span>rotationY, Vector3.<span style="color: #0000FF;">left</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			transform.<span style="color: #0000FF;">localRotation</span> <span style="color: #008000;">=</span> originalRotation <span style="color: #008000;">*</span> yQuaternion<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">void</span> Start <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// Make the rigid body not change rotation</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>rigidbody<span style="color: #000000;">&#41;</span>
			rigidbody.<span style="color: #0000FF;">freezeRotation</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
		originalRotation <span style="color: #008000;">=</span> transform.<span style="color: #0000FF;">localRotation</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">float</span> ClampAngle <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span> angle, <span style="color: #FF0000;">float</span> min, <span style="color: #FF0000;">float</span> max<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>angle <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #008000;">-</span>360F<span style="color: #000000;">&#41;</span> 			angle <span style="color: #008000;">+=</span> 360F<span style="color: #008000;">;</span> 		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>angle <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> 360F<span style="color: #000000;">&#41;</span>
			angle <span style="color: #008000;">-=</span> 360F<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> Mathf.<span style="color: #0000FF;">Clamp</span> <span style="color: #000000;">&#40;</span>angle, min, max<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now, there are a few little things in those comments that might be confusing to an absolute beginner.</p>
<p><code><br />
///To make an FPS style character:<br />
/// - Create a capsule.</code><br />
We&#8217;re good here.</p>
<p><code>/// - Add a rigid body to the capsule</code><br />
With the Capsule selected, choose Menu-&gt;Component-&gt;Rigid Body</p>
<p><code>/// - Add the MouseLook script to the capsule.</code><br />
Drag the MouseLook script from the Project panel onto the Capsule&#8217;s empty area in the Inspector</p>
<p><code>///   -&gt; Set the mouse look to use LookX. (You want to only turn character but not tilt it)</code><br />
Set the &#8220;Axes&#8221; to &#8220;MouseX&#8221;</p>
<p><code>/// - Add FPSWalker script to the capsule</code><br />
Drag this to the Capsule&#8217;s Inspector from Project panel-&gt;Standard Assets-&gt;Scripts</p>
<p>Once you do all this stuff, hit the play button up top. If you&#8217;ve done it right, the the ASWD keys will move your capsule around and your mouse will turn it in the Scene view. Sweet, right?</p>
<p>The next steps actually hook a camera up to the Capsule. Unity relies on object hierarchies much like 3D modeling software does. So if I were in 3DSMax and I wanted to have a camera attached to this capsule, I&#8217;d parent the camera to the capsule&#8230; and that&#8217;s exactly what we do here.</p>
<p>So, in the Hierarchy panel, drag the Main Camera onto the Capsule. Now again, just like in 3D software, the transform of the camera is now relative to the capsule instead of the world. So let&#8217;s put the Camera at 0,0,0 in the Capsule&#8217;s space by selecting the camera, clicking the little Gear icon next to its Transform in the Inspector panel, and choosing &#8220;Reset&#8221;. Notice that X,Y,Z all go back to 0? You may also notice the Game view updating a bit. Hard to tell since the Terrain is completely flat. In fact, let&#8217;s paint some test terrain real quick to have a frame of reference.</p>
<p>Choose the Terrain in the Hierarchy panel. Notice in the inspector there is a series of icons for painting terrain? Just get in there and mess it up a bit. We just need a few hills and valleys to be able to tell what&#8217;s going on. Click in the Scene view and either mousewheel to zoom out or hit F to expand the view. Then click the Raise Terrain button on the Terrain inspector and paint some hills. Try not to paint exactly on the Capsule since it will put the Capsule below the Terrain. Just do some stuff off in the distance so we can tell what&#8217;s going on.</p>
<p>Now let&#8217;s run the game and see what we see. Nice! If you click in the game view, you&#8217;ll see that the mouse now turns the camera and ASWD moves, all in first person.</p>
<p>The last step is to make it so the camera can look up and down. Going back to the script&#8217;s comments,</p>
<p><code><br />
/// - Add a MouseLook script to the camera.<br />
///   -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)</code></p>
<p>So let&#8217;s do just that. With the Main Camera selected, drag that MouseLook script over and set the Axes to MouseY. Hey, we can look up and down. Nice.</p>
<p>Ok so lastly, you need to be introduced as early as possible to one of the big gotchas in Unity 2.5. Notice that the game is still running? Click the Play button while looking at the Inspector panel with the Main Camera selected. </p>
<p>Hey! Our MouseLook disappeared! WTF? Yes, ANYTHING you do while the game is running is considered an &#8220;experiment&#8221; and is NOT saved. You could work for hours and lose all of it. So get in the habit VERY early of knowing when you are and are not playing the game. Got it? <img src='http://variancetheory.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://variancetheory.com/digging-into-unity3d-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Digging into Unity3D &#8211; A Flex Developer/Technical Artist&#8217;s Perspective</title>
		<link>http://variancetheory.com/digging-into-unity3d-a-flex-developertechnical-artists-perspective/</link>
		<comments>http://variancetheory.com/digging-into-unity3d-a-flex-developertechnical-artists-perspective/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 20:47:55 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://variancetheory.com/?p=380</guid>
		<description><![CDATA[Yeah that title is kinda weird, right? Well that&#8217;s my background. I wrote Mrs. Riley&#8217;s PageBuilder with Flex and was a Technical Artist for Vicarious Visions for over 3 years, working with a lot of awesome 3D technologies including VV&#8217;s Alchemy and 3DSMax while making games there. I&#8217;ve always wanted to work on my own [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah that title is kinda weird, right? Well that&#8217;s my background. I wrote <a href="http://mrsriley.com">Mrs. Riley&#8217;s PageBuilder</a> with Flex and was a Technical Artist for Vicarious Visions for over 3 years, working with a lot of awesome 3D technologies including VV&#8217;s Alchemy and 3DSMax while making games there. I&#8217;ve always wanted to work on my own game &#8211; as far back as college. The problem has always been finding a toolset that has the capabilities in 3D to take advantage of my art skills while isolating me from the real nitty gritty engine coding duties that are far too involved for me to tackle alone.</p>
<p>A few years back I came across the Unity engine when it was Mac only. I was pretty interested, but it&#8217;s only recently that I&#8217;ve started to really have a go at it and so far, I&#8217;m impressed. Unity is very visual. A scene has a hierarchy of objects that all have a visual representation in the world &#8211; some more as proxies to code, some as real 3d assets. But that organizational difference is really important for my way of thinking and learning. I suspect that there are a lot of other folks that feel the same way because it&#8217;s really gained traction over the past year. And of course it doesn&#8217;t hurt that they provide a version for developing iPhone games.</p>
<p>So, my first few hours have been spent going over tutorials. Unity provides a few projects with nicely written PDF tutorials <a href="http://unity3d.com/support/resources/tutorials/">here</a>. So far I&#8217;ve spent time with only the 2D Platform Tutorial. It&#8217;s just a simple character on a couple platforms along with controller logic, physics, particles, a skybox, and some UI. Ok so, maybe not that simple. In fact, what I really want to find is a dead simple hello world type tutorial. I&#8217;d like to create a terrain, import a model from Max, hook up some kind of control via the keyboard, and move the model around the world. I don&#8217;t even care if the camera follows around this point. I&#8217;ve looked for a few minutes and haven&#8217;t seen anything so far.</p>
<p>So that&#8217;s the next post. Right now though I haven&#8217;t been this excited by a piece of software since I drove up to Toronto with my Dad in 1996 to get a copy of 3DSMax 1.0 Educational. (it was $995 Canadian) That was the best investment of my career and I have a feeling that Unity will be another great one.</p>
]]></content:encoded>
			<wfw:commentRss>http://variancetheory.com/digging-into-unity3d-a-flex-developertechnical-artists-perspective/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
