<?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>Slawia</title>
	<atom:link href="http://carpe.com.au/slawia/feed/" rel="self" type="application/rss+xml" />
	<link>http://carpe.com.au/slawia</link>
	<description>Games, iPhones and Unity</description>
	<lastBuildDate>Mon, 05 Oct 2009 04:18:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Not dead, just resting</title>
		<link>http://carpe.com.au/slawia/2009/09/not-dead-just-resting/</link>
		<comments>http://carpe.com.au/slawia/2009/09/not-dead-just-resting/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 01:32:00 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=235</guid>
		<description><![CDATA[A post in which I assure you we are working in the background on our first game and I list developer blogs and review sites I follow.]]></description>
			<content:encoded><![CDATA[<p>I have just realised that we have not posted anything in the last two weeks. It is time to remedy that. We may not have posted but we have not been sitting idle. In line with <a title="Our Philosophy" href="http://carpe.com.au/slawia/2009/08/development-philosophy/" target="_self">our philosophy</a> we are getting things done in the background.</p>
<p>We are working on our first game. It is perhaps not the game either of us would choose do, nor have we done any research to find out if there is a niche for it. It is an experiment.</p>
<p>One thing I have been doing is reading the experiences of other independent developers out there. There are many development blogs for people working on iPhone games and using Unity.</p>
<p>I am subscribing to new blogs everyday, but three that stand out for me at the moment are:</p>
<p><a title="Tiny Tim Games" href="http://www.tinytimgames.com" target="_blank">Tiny Tim Games</a> &#8211; Jerrod Putman and Shannon Kay are a husband and wife team the produced <a title="Sheep Stacker" href="http://www.tinytimgames.com/games/sheepstacker/" target="_blank">Sheep Stacker</a> with Unity and are working on their second game.</p>
<p><a href="http://gtjuggler.blogspot.com" target="_blank">GTProductions</a> &#8211; Alex Schwartz is putting finishing touches on his first game, Spring Fling, also with Unity.</p>
<p><a href="http://retrodreamer.com" target="_blank">Retro Dreamer</a> &#8211; Craig Sharpe and Gavin Bowman are and artist/programmer team (there seem to be a lot of two person teams out there) who produced <a title="Sneezies" href="http://retrodreamer.com/sneezies.htm" target="_blank">Sneezies</a>.</p>
<p>I have to mention Kristopher Peterson who is producing a game call <a title="Revolt Game" href="http://revoltgame.blogspot.com" target="_blank">Revolt </a>single handed with Unity. His posts are mainly of test renders of him game, but they are oh so pretty</p>
<p>I have started getting more serious about what is happening in the world of iPhone games. I am following a couple of review sites. I am becoming increasingly aware that there are a lot of developers and a lot of games out there. Creating an iPhone game is not a license to print money. It actually takes time and effort to get your creation noticed. That is were the review sites come in. Getting some exposure on one or more of these sites can help lift a game from obscurity.</p>
<p>Two sites I am following at the moment are <a title="Touch Arcade" href="http://toucharcade.com" target="_blank">Touch Arcade</a> and <a title="App Gamer" href="http://appgamer.net" target="_blank">App Gamer</a>. App Gamer recently ran a feature on <a href="http://appgamer.net/features/2009/sep/3/industry-game-marketing-and-pr-lock-it-down/" target="_blank">marketing iPhone apps</a>.</p>
<p><em>I am sure there are many more blogs and review sites out there, if you know of any interesting ones let me know.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/09/not-dead-just-resting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Our Game Development Philosophy</title>
		<link>http://carpe.com.au/slawia/2009/08/development-philosophy/</link>
		<comments>http://carpe.com.au/slawia/2009/08/development-philosophy/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 03:52:37 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Game Design]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=217</guid>
		<description><![CDATA[Marc and I have been talking about game pre-production, project management and our immediate goals. Right now those goals are: Produce a complete game for deployment online and/or on iPhone. Work to our strengths &#8211; Marc&#8217;s, Justin&#8217;s and Unity&#8217;s strengths. Make it polished, but do it quickly. If we are going to succeed then our [...]]]></description>
			<content:encoded><![CDATA[<p>Marc and I have been talking about game pre-production, project management and our immediate goals. Right now those goals are:</p>
<ul>
<li>Produce a complete game for deployment online and/or on iPhone.</li>
<li>Work to our strengths &#8211; Marc&#8217;s, Justin&#8217;s and Unity&#8217;s strengths.</li>
<li>Make it polished, but do it quickly.<span id="more-217"></span></li>
</ul>
<p>If we are going to succeed then our guiding principle must be to <strong>keep it simple</strong>. Keeping things simple works on many levels.</p>
<p>Casual games are played on the spur of the moment, usually in small intervals. To succeed the game must be easy for the user to understand.  Both the object of the game and its controls need to be simple and intuitive.</p>
<p>The target platform will be the iPhone and web browser player. These platforms have limited capacity both in terms of file/download size and computing power. Game assets and logic need to be kept small and simple  not to over-tax the platform.</p>
<p>Casual games, with their need to be intuitive and light, benefit greatly from an iterative development cycle. Assemble the barest minimum game-play needed for the game then test, test and test some more. When new features are added to this minimalist build they then need justify their inclusion through testing. Starting simple allows us to get to testing early and often.</p>
<p>Finally, as a very small team working in spare time the scope of the project has to be something that can be realistically completed in the time we have. The time we have is however long our enthusiasm lasts.</p>
<p>Here are soem other people&#8217;s thoughts on casual games and agile development:</p>
<ul>
<li>Jacob Williams&#8217;  <a title="Maze Shifter post mortem" href="http://learnunity3d.com/?p=98" target="_blank">post mortem of Maze Shifter</a>, his first iPhone game.</li>
<li>Tom Higgins&#8217; <a title="Causual Games as a business" href="http://unity3d.com/support/resources/articles/casual-business" target="_blank">Casual Games as a business</a> &#8211; I think you have to take the examples of money made with casual games with a large grain of salt, but the points on what makes a good casual game is gold.</li>
<li>37signal&#8217;s <a title="Getting Real ebook" href="http://gettingreal.37signals.com/" target="_blank">Getting Real ebook</a> &#8211; They are writing about creating web applications, but their philosophy of agile, user-centered development is a good fit for indie game development.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/development-philosophy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity Wheel Collider: Redux</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-redux/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-redux/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 12:33:20 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=204</guid>
		<description><![CDATA[When I posted my wheel collider demo on the Unity forum I got some good feedback. This post includes an updated scene and script.]]></description>
			<content:encoded><![CDATA[<p><em>This is part of an ongoing mission to explore making a simple controlled vehicle using the Unity Wheel Collider. See the </em><a style="color: #990000; text-decoration: underline;" title="Unity Wheel Collider: Introduction" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-introduction/" target="_self"><em>introduction</em></a><em> for a chapter list.</em></p>
<p>When I posted my <a title="Previous version" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-conclusion/" target="_self">first wheel collider demo</a> to the <a title="Unity forum thread about this project" href="http://forum.unity3d.com/viewtopic.php?t=30499" target="_blank">Unity forum</a> I got some really good feedback. So now I updated my scene and script to iron out odd behaviours and add new features. I have posted the scene in a web player and the complete updated script again.<span id="more-204"></span></p>
<p><em>Please view the full post to see the Unity content.</em></p>
<p>For completeness sake here is the updated script.</p>
<pre class="brush: jscript; title: ;">var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;

var wheelFL : Transform;
var wheelFR : Transform;
var wheelML : Transform;
var wheelMR : Transform;
var wheelRL : Transform;
var wheelRR : Transform;

var steer_max = 20;
var motor_max = 40;
var brake_max = 100;
var steerSpeed = 20;

private var steer = 0;
private var forward = 0;
private var back = 0;
private var brakeRelease = false;
private var motor = 0;
private var brake = 0;
private var reverse = false;
private var speed = 0;

function Start() {
rigidbody.centerOfMass = Vector3(0, -0.05, 0);
}

function FixedUpdate () {

speed = rigidbody.velocity.sqrMagnitude;
steer = Input.GetAxis(&quot;Horizontal&quot;);
forward = Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), -1, 0);

if(speed == 0 &amp;&amp; forward == 0 &amp;&amp; back == 0) {
brakeRelease = true;
}

if(speed == 0 &amp;&amp; brakeRelease) {
if(back &gt; 0) { reverse = true; }
if(forward &gt; 0) { reverse = false; }
}

if(reverse) {
motor = -1 * back;
brake = forward;
} else {
motor = forward;
brake = back;
}
if (brake &gt; 0 ) { brakeRelease = false; };

rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;

if ( steer == 0 &amp;&amp; frontWheel1.steerAngle != 0) {
if (Mathf.Abs(frontWheel1.steerAngle) &lt;= (steerSpeed * Time.deltaTime)) {
frontWheel1.steerAngle = 0;
} else if (frontWheel1.steerAngle &gt; 0) {
frontWheel1.steerAngle = frontWheel1.steerAngle - (steerSpeed * Time.deltaTime);
} else {
frontWheel1.steerAngle = frontWheel1.steerAngle + (steerSpeed * Time.deltaTime);
}
} else {
frontWheel1.steerAngle = frontWheel1.steerAngle + (steer * steerSpeed * Time.deltaTime);
if (frontWheel1.steerAngle &gt; steer_max) { frontWheel1.steerAngle = steer_max; }
if (frontWheel1.steerAngle &lt; -1 * steer_max) { frontWheel1.steerAngle = -1 * steer_max; }
}
frontWheel2.steerAngle = frontWheel1.steerAngle;
wheelFL.localEulerAngles.y = frontWheel1.steerAngle;
wheelFR.localEulerAngles.y = frontWheel2.steerAngle;

wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelMR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelML.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);

}</pre>
<p>What&#8217;s changed?</p>
<p>The truck tended to launch itself into space when going over jumps. Lots of fun but not very realistic. To address this I did two things.</p>
<p>First I scaled the truck down in size so it is about three meters long. In the first version it was over eleven meters long and nine meters tall &#8211; it was the size of a small two storey apartment. <strong>Using the correct scale is vitally important when using physics.</strong> The correct scale is 1:1 with the real world.</p>
<p>Second I increased the drag on the truck. This slows it down faster and makes it feel generally heavier.</p>
<p>I have added smoothing to the steering. Now when you turn left and right the wheels turn smoothly until they reach the maximum steering angle. When you release the steering controls the wheels rotate back to centered.</p>
<p>I changed the way the truck switches into and out of reverse. If you use the brake to stop the truck moving you have to release the brake key and then press it again to have the truck change into reverse (or forward) gear.</p>
<p>I got the middle set of wheels to rotate. I know I said I was not going to do that, but it bugged me that they did not move.</p>
<p>Finally I changed the wrap mode on the skybox textures from repeat to clamp. This got rid of the visible seams between the skybox textures. (Thanks to NickAVV on the forum for that one).</p>
<p><em>So what do you think? See anything else that could do with improving? If so let me know in the comments.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-redux/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Entering game pre-development phase</title>
		<link>http://carpe.com.au/slawia/2009/08/entering-game-pre-development-phase/</link>
		<comments>http://carpe.com.au/slawia/2009/08/entering-game-pre-development-phase/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 10:13:23 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Game Design]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=190</guid>
		<description><![CDATA[Its the end of Justins trial demo of Unity and we have made the decision to get him a full indie license. I&#8217;d say our overall impression of Unity is its easy to get something happening quickly and if you you are willing to invest some time, you can make some good commercial games with [...]]]></description>
			<content:encoded><![CDATA[<p>Its the end of Justins trial demo of Unity and we have made the decision to get him a full indie license. I&#8217;d say our overall impression of Unity is its easy to get something happening quickly and if you you are willing to invest some time, you can make some good commercial games with it. As Justin said to me  &#8211;  &#8220;its got legs&#8221;.</p>
<p>The best way for us to get more proficient at Unity is to commit to making a simple game with it. We have elected to do a small project, a delivery game, where the player controls courier van picking up and dropping of cargo, in 3rd person camera view. It might not seem as inspiring as Grand Theft Auto, but we have to start small. So many times I seen on game making forums, people posting about how they are going to make the next WOW. Their first project and  its gonna be a WOW killer! Not surprisingly, they never do. I just wonder if Justin and I are thinking small enough!</p>
<p>I am an artist and I want to be modelling, texturing and animating <strong>yesterday</strong>, but first things first &#8211; we need to write a game design document. This is where we&#8217;ll explain the game play supported by diagrams and have a list of assets (code and art ) required to make it all happen. Also there is no point designing the whole game right now. We need to design the core repeatable game mechanics, make sure they are fun, before we go full steam ahead. This is the pre-development stage of our game where will make a test level with all of the key game mechanics functioning.</p>
<p>We&#8217;ll post our design document when we have finished a presentable draft.</p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/entering-game-pre-development-phase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Talking iPhone development with The Doctor</title>
		<link>http://carpe.com.au/slawia/2009/08/talking-iphone-development-with-the-doctor/</link>
		<comments>http://carpe.com.au/slawia/2009/08/talking-iphone-development-with-the-doctor/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 08:53:52 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=176</guid>
		<description><![CDATA[Marc talks to the Doctor, a friend with years of professional experience as a content creator and producer for mobile phones, about the realities of developing for the iPhone.]]></description>
			<content:encoded><![CDATA[<p><em>Marc and I have dabbled in making games for phones before. More specifically we came up with a few prototypes for Flash Lite games. The Doctor (name withheld) is in the business of creating and producing Flash Lite content for phones. He has been making a living from it for several years now.</em></p>
<p><em></em><em>This conversation took place at the beginning of August over IM between Marc and the Doctor. We have reproduced it here with permission because we thought it would be interesting to anyone looking at iPhone development. There has been a minimum of editing done to make the original IM chat presentable.</em></p>
<p><em></em><strong>Marc:</strong> You developing for iPhone yet?</p>
<p><strong>Doctor:</strong> G&#8217;day Marc &#8230; have come close a few times, but no, not yet.</p>
<p><strong>Marc: </strong>Whats stopping you? There really is gold in them hills.</p>
<p><strong>Doctor:</strong> Really? Do you have any in your pocket?</p>
<p><strong>Marc:</strong> lol, no! not yet, and will let you know if i do &#8211; Justin and I only dusted off the iPhone dev kit stuff 2 weeks ago &#8211; life gets in the way.</p>
<p><strong>Doctor:</strong> Here&#8217;s my list of hurdles (just my own personal list) &#8211; no Mac hardware, no experience with ObjectiveC, approval process nightmare stories, personal knowledge of iPhone developer colleagues making less than what I make from Nokia devices. Oh &#8230; and time <img src='http://carpe.com.au/slawia/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Marc:</strong> Personal knowledge of iPhone developer colleagues &#8211; this point is the most concerning. What are the key issues they have had?</p>
<p><strong>Doctor:</strong> I have many friends all over the world who are getting very poor returns. The App store is an over crowded swamp of content now, and content discoverability is a real issue.</p>
<p><strong>Marc:</strong> Good points</p>
<p><strong>Doctor:</strong> The global market of iPhone owners, in ratio to the amount of content, stacks the chips very much with the big development companies and not independent devs. Although of course there are some exceptions and some indies still hit a rich vein for a period of time.</p>
<p>Firemint have struck gold with Flight Control and Real Racer, but they have been in the mobile game business for over 10 years.</p>
<p>Don&#8217;t get me wrong &#8211; I own an iPhone and the experience with downloading apps is great. However, monetizing those apps for the developer is just as much an issue for that platform as it is for others (IMHO)</p>
<p><strong>Marc:</strong> What you have written is really food for thought. The middle ware Justin and I are learning is cross platform mac/pc/iphone &#8211; Unity &#8211; you must have heard of it. If it doesn&#8217;t pan out with iPhone we can always try our hands and some indy games with the same software.</p>
<p><strong>Doctor:</strong> Yep, I know Unity</p>
<p><strong>Marc:</strong> Well? Tinkered with it?</p>
<p><strong>Doctor:</strong> You should also check out Corona as a platform for easier iPhone development. I have some Flash Lite friends who have published apps in the App Store and have used it with quite good success.</p>
<p>No, I haven&#8217;t actually used Unity</p>
<p><strong>Marc:</strong> Is Corona 3d?</p>
<p><strong>Doctor:</strong> <a href="http://www.anscamobile.com/corona/" target="_blank">http://www.anscamobile.com/corona/</a></p>
<p><strong>Marc:</strong> Thanks for the link</p>
<p><strong>Doctor:</strong> No worries mate</p>
<p><strong>Marc:</strong> Happy trails Doctor &#8211; well, if Justin and I have anything to crow about in the next few months we&#8217;ll let you know.</p>
<p><strong>Doctor:</strong> I hope you do mate, I&#8217;d be the first to congratulate you <img src='http://carpe.com.au/slawia/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Marc:</strong> We may be some time&#8230;.because we are new to it all&#8230;</p>
<p><strong>Doctor:</strong> I&#8217;m personally looking for new opportunities (in mobile and beyond) so I&#8217;ll let you know what happens with that.</p>
<p><strong>Marc:</strong> Please do mate &#8211; all the best</p>
<p><strong>Doctor:</strong> Cheers</p>
<p><em>What do think? Have you had any commercial experience with iPhone apps? If so we would love to hear your opinion in the comments below.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/talking-iphone-development-with-the-doctor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity Wheel Collider: Conclusion</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-conclusion/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-conclusion/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 23:00:18 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=165</guid>
		<description><![CDATA[The finished Unity Wheel Collider scene in the Unity web player. ]]></description>
			<content:encoded><![CDATA[<p><em>This is part of an ongoing mission to explore making a simple controlled vehicle using the Unity Wheel Collider. See the </em><a title="Unity Wheel Collider: Introduction" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-introduction/" target="_self"><em>introduction</em></a><em> for a chapter list.</em></p>
<p>As a conclusion to this short series on the wheel collider I present the finished scene. Enjoy!<span id="more-165"></span></p>
<p><em>Please view the full post to see the Unity content.</em></p>
<p><strong>Update: </strong>I have made some fixes and changes to this scene and script. See the latest version <a title="Unity Wheel Collider: Redux" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-redux/" target="_self">here</a>.</p>
<p><em>What do you think? I would love to hear your feedback. Post in the comments below.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-conclusion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unity Wheel Collider: Part 3</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-3/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-3/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 11:45:00 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=143</guid>
		<description><![CDATA[The wheels are fixed so they appear to spin and steer, reverse gear is added and the complete updated script provided with commentary.]]></description>
			<content:encoded><![CDATA[<p><em>This is part of an ongoing mission to explore making a simple controlled vehicle using the Unity Wheel Collider. See the </em><a title="Unity Wheel Collider: Introduction" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-introduction/" target="_self"><em>introduction</em></a><em> for a chapter list.</em></p>
<h1>The Devil in the Details</h1>
<p>Now we have a very basic control script in place I am going to add some pretties.<span id="more-143"></span></p>
<h2>Some Clean Up</h2>
<p>If you remember at the end of <a title="Part 2" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-2/" target="_self">Part 2</a> I bemoaning the fact that our truck was very liable to do wheelies and roll over when cornering. The solution to both those problems is to lower the center of mass on the <em>rigidbody</em> on the truck. This will make the truck much more stable.</p>
<p>Moving the center of mass of a <em>rigidbody</em> requires script. It only needs to done once when the scene first starts, so we will add a start function to our script.</p>
<pre class="brush: jscript; title: ;">function Start(){
rigidbody.centerOfMass = Vector3(0, -0.05, 0);
}</pre>
<p>This script moves the center of mass down (the negative Y direction) from its original position at the center of the truck&#8217;s <em>rigidbody</em>. I had to play around with the value here to get something that looks right. If the center of mass id too low it can be effectively below the plane of the ground, then when the truck turns at speed it leans into the corner, not out. That&#8217;s good if it were a tilt train, but not too realistic for our top heavy truck.</p>
<p><strong>Backing Up</strong></p>
<p>Our truck goes forward and stops, but does not go in reverse. To fix that I want to test if the truck is stationary and the backward (S) key is pressed. If so then we reverse the effects of the forward and back keys: the back key will accelerate the truck in the reverse direction and the forward key (W) will apply the brakes. I will also need to test for changing back into forward gear when the truck stops reversing.</p>
<pre class="brush: jscript; title: ;">speed = rigidbody.velocity.sqrMagnitude;

steer = Mathf.Clamp(Input.GetAxis(&quot;Horizontal&quot;), -1, 1);
forward = Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), -1, 0);

if(speed == 0) {
  if(back &gt; 0) { reverse = true; }
  if(forward &gt; 0) { reverse = false; }
}

if(reverse) {
  motor = -1 * back;
  brake = forward;
} else {
  motor = forward;
  brake = back;
}</pre>
<p>There are more variables here. Speed is the velocity of the truck. When it&#8217;s magnitude is zero we know the truck is stationary, if only briefly. If the truck is stationary we check to see if forward or back are being pressed and set the state of reverse variable appropriately.</p>
<p>I have changed the capturing of user input so it is separate from the motor and brake. This is so when in reverse we can swap the actions on the user controls.</p>
<h2>Turning the Wheels</h2>
<p>There are two rotations we need to deal with when it comes to turning the wheels. The first is turning the front wheels to match the steering. The second is to rotate the wheels to simulate their rolling along the ground.</p>
<p>To turn the wheels with the script we first need to let the script know what the wheels are. So I add some public variables for the wheel meshes so we can hook them up in the script inspector.</p>
<pre class="brush: jscript; title: ;">var wheelFL : Transform;
var wheelFR : Transform;
var wheelRL : Transform;
var wheelRR : Transform;</pre>
<p>To simulate the steering we match the Y rotation of the front wheel meshes to the same <em>steerAngle</em> as the corresponding wheel colliders.</p>
<pre class="brush: jscript; title: ;">wheelFL.localEulerAngles.y = steer_max * steer;
wheelFR.localEulerAngles.y = steer_max * steer;</pre>
<p>I used <em>localEulerAngles</em> here because I want to set the wheels to a specific angle. The local version of <em>eulerAngles</em> means the angle is relative to the truck, not relative to the world. I only set the Y component so the wheel is free to rotate around the Z axis.</p>
<p>Then we tie the rotation of the wheel meshes to the (virtual) rotation of the wheel colliders.</p>
<pre class="brush: jscript; title: ;">wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);</pre>
<p>The <em>rpm</em> of the wheels (handily provided by the wheel collider) is divided by 60 to get revolutions per second, and multiplied by 360 to get the degrees rotated per second (360 / 60 = 6). I found I had to stick a minus sign in here to have the wheels turn in the right direction. We then multiply by <em>deltaTime</em> (the time passed since the last frame in seconds) to find the wheel&#8217;s rotation in since the last frame. We rotate the wheel meshes by that amount.</p>
<p>In this case we use <em>rotate</em> rather than <em>eulerAngles</em> because rotate is cumulative.</p>
<h2>The Complete Script</h2>
<pre class="brush: jscript; title: ;">var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;

var wheelFL : Transform;
var wheelFR : Transform;
var wheelRL : Transform;
var wheelRR : Transform;

var steer_max = 20;
var motor_max = 10;
var brake_max = 100;

private var steer = 0;
private var forward = 0;
private var back = 0;
private var motor = 0;
private var brake = 0;
private var reverse = false;
private var speed = 0;

function Start() {
rigidbody.centerOfMass = Vector3(0, -0.05, 0);
}

function FixedUpdate () {

speed = rigidbody.velocity.sqrMagnitude;
steer = Mathf.Clamp(Input.GetAxis(&quot;Horizontal&quot;), -1, 1);
forward = Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), -1, 0);

if(speed == 0) {
if(back &gt; 0) { reverse = true; }
if(forward &gt; 0) { reverse = false; }
}

if(reverse) {
motor = -1 * back;
brake = forward;
} else {
motor = forward;
brake = back;
}

rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;

frontWheel1.steerAngle = steer_max * steer;
frontWheel2.steerAngle = steer_max * steer;
wheelFL.localEulerAngles.y = steer_max * steer;
wheelFR.localEulerAngles.y = steer_max * steer;

wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);

}</pre>
<h2>What Next</h2>
<p>At this stage I think we have a simple but serviceable script. There are a few more things that can be added to improve it. In this case our truck has six wheels and I have only added wheel colliders to four of them. Adding the other two would simply be a case of duplicating the rear wheels throughout the script.</p>
<p>There are many cosmetic things that could be done like adding brake and reversing lights that react to the user&#8217;s input as well as engine noise.</p>
<p>Speaking of engines the truck does not accelerate like a real vehicle. Hitting forward applies a constant torque to the wheels. In a real vehicle revs, power-bands and gears mean that torque is anything but constant. However simulating that is beyond what I set out to achieve here.</p>
<p>Finally there are the other pieces of setting and behaviour that would make the simulation more game like. Using terrain instead of a dead flat plane would make driving more interesting. Having the camera follow behind the truck would make it much easier to drive.</p>
<p><em>This is one of my very first scripts in Unity. Feel free to take it, try it and tweak it. I would love to hear any feedback anyone has using it. If you have questions about how it works or know how I could improve it please let me know in the comments below.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unity Wheel Collider: Part 2</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-2/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-2/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 03:36:40 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=94</guid>
		<description><![CDATA[A simple vehicle control script is explained and added to our wheel collider project.]]></description>
			<content:encoded><![CDATA[<p><em>This is part of an ongoing mission to explore making a simple controlled vehicle using the Unity Wheel Collider. See the </em><a title="Unity Wheel Collider: Introduction" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-introduction/" target="_self"><em>introduction</em></a><em> for a chapter list.</em></p>
<h1>The World&#8217;s Simplest Car Control Script</h1>
<p>In <a title="Part 1" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-1/" target="_self">Part 1</a> I put some wheels on Marc&#8217;s truck and let it roll down a slope under the force of gravity. In this post I want to add the simplest of vehicle control scripts to the truck.</p>
<p>So without further ado here is the world&#8217;s simplest car control script for Unity:</p>
<pre class="brush: jscript; title: ;">var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;

var steer_max = 20;
var motor_max = 10;
var brake_max = 100;

private var steer = 0;
private var motor = 0;
private var brake = 0;

function FixedUpdate () {

steer = Mathf.Clamp(Input.GetAxis(&quot;Horizontal&quot;), -1, 1);
motor = Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), 0, 1);
brake = -1 * Mathf.Clamp(Input.GetAxis(&quot;Vertical&quot;), -1, 0);

rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;

frontWheel1.steerAngle = steer_max * steer;
frontWheel2.steerAngle = steer_max * steer;

}</pre>
<p>So lets go through it bit by bit.</p>
<p>The first four lines create public variables for the car&#8217;s wheel colliders. When a script is added to a game object public variables appear in the script inspector. The plan is to add the script to the truck body game object then hook each of the wheel colliders to these variables using the script inspector.</p>
<p>The next three lines define public variables for use in our script. These are the maximum steer angle, motor torque and brake torque. By making them public I can change them easily in script inspector.</p>
<p>The next three lines are some private variables for use in the script. Specifically they will be used to temporarily store user inputs.</p>
<p>The FixedUpdate function is the heart of the script. The FixedUpdate function is run once every frame that the physics of the scene is updated.</p>
<p>In the function I grab the user input for steering, motor and brakes. These are the ASWD keys by default. Input.GetAxis(&#8220;Horizontal&#8221;) gets the A and D key presses for left and right. I will use this to steer the truck. Input.GetAxis(&#8220;Vertical&#8221;) gets W and S key presses. In this case I want W to apply the accelerator and S to apply the brake. So I have clamped, or restricted, the vertical input returns so I know when they are positive (the W key, going forward) and negative (the S key, going backward or braking).</p>
<p>With the user input giving me steering, motor and brake I then apply those to the wheel colliders. The motor and brake torques are applied to both the rear wheels and the steering angle to the front wheel colliders. MotorTorque, brakeTorque and steerAngle are all properties of the Unity wheel collider.</p>
<h2>Using the script</h2>
<p>The script is applied the the main truck object. Once applied the public settings for it turn up in the inspector. There are four slots for wheel colliders. Drag the wheel collider ojects from the hierarchy to the appropriate slots in the script inspector.</p>
<div id="attachment_117" class="wp-caption aligncenter" style="width: 371px"><img class="size-full wp-image-117" title="wc_02_01" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/wc_02_01.jpg" alt="The script in the inspector" width="361" height="151" /><p class="wp-caption-text">The script in the inspector</p></div>
<p>There were a few other tweaks to be made to the scene before testing. First I leveled the ground plane out again. Then I added a box collider to the truck object. Without the box collider the truck mesh will pass though the ground plane with the truck rolls over&#8230; and trust me, it will roll over.</p>
<p>Stomp on the gas and you will find the truck goes into a permanent wheelie. Try and turn a corner at speed and the whole thing is liable to tip over. Obviously there are issues about how much the truck weighs and where its centre of gravity is. Having not changed the default weight of the truck from one kilogram it must have a density much less than styrofoam &#8211; no wonder it&#8217;s flying about. (EDIT: I have subsequently learned that it is the placement of the truck&#8217;s center of gravity, see the next chapter for how to fix it.)</p>
<h2>Next Steps</h2>
<p>You may notice as you drive around that some things are still off with our truck. The tyres do not turn as the truck moves and the front tyres do not turn with the steering. There is also suspension associated with the wheel colliders which is not being reflected in the tyres. We will fix these cosmetic issues in the <a title="Part 3" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-3/" target="_self">next part</a>.</p>
<p><em>Are you following along and have questions or wisdom to share? Leave a comment below.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Unity Scripting: the Artist&#8217;s Perspective</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-scripting-the-artists-perspectiv/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-scripting-the-artists-perspectiv/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 02:56:36 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=105</guid>
		<description><![CDATA[I explain how easy Unity scripting is for non-programmers.]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-106" title="scripting" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/scripting-150x150.png" alt="scripting" width="150" height="150" />Just did the <a href="http://download.unity3d.com/support/Tutorials/2%20-%20Scripting%20Tutorial.pdf" target="_blank">&#8220;Introduction to Scripting with Unity&#8221;</a>. Justin, who&#8217;ll be doing the brunt of the scripting, has already done it, but I thought that an artist who wants to work with Unity should to do it as well. It really helped me understand how Unity works.</p>
<p>If I was to explain it to another artist broadly how Unity works, you import your game art into the program and attach scripts to the art to make it do what you want. Literally drag the icon of the scripts you need onto the object. Of course you need to write the scripts, but the tutorial takes you through some of the core scripts that really are the building blocks of games.</p>
<p>I hate scripting, but I found this tutorial easy to follow. You just cut and paste the examples into Unity. It really helped me understand how Unity works. I think I may even have a go at script or two myself. I am more likely to take existing scripts and modify them. You can find loads of them here at the <a href="http://www.unifycommunity.com/wiki/index.php?title=Scripts" target="_blank">Unify Community</a></p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-scripting-the-artists-perspectiv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity Wheel Collider: Part 1</title>
		<link>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-1/</link>
		<comments>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-1/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 12:23:05 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://carpe.com.au/slawia/?p=50</guid>
		<description><![CDATA[In this part I step through setting up a truck model with wheel colliders.]]></description>
			<content:encoded><![CDATA[<p><em>This is part of an ongoing mission to explore making a simple controlled vehicle using the Unity Wheel Collider. See the </em><a title="Unity Wheel Collider: Introduction" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-introduction/" target="_self"><em>introduction</em></a><em> for a chapter list.</em></p>
<h1>Putting some wheels on the truck</h1>
<p>In this part of the mission I am going to step through setting up the truck model with wheel colliders. At the end of it we should be able to have the truck roll down a slope under the effects of gravity.</p>
<p>First a created a new project in Unity and then imported the truck and wheel assets given to me by Marc as 3ds objects. I asked for the wheels separately so I could make them into a prefab and repeat them around the truck. I can also eventually rotate the wheel meshes so they appear to be rolling across the ground.</p>
<div id="attachment_80" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-80 " title="wc_01_01" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/wc_01_01.jpg" alt="Little blue truck with wheels attached" width="460" height="360" /><p class="wp-caption-text">Little blue truck with wheels attached</p></div>
<div id="attachment_81" class="wp-caption alignleft" style="width: 276px"><img class="size-full wp-image-81" title="wc_01_04" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/wc_01_04.jpg" alt="The wheel collider is found under the Physics components" width="266" height="363" /><p class="wp-caption-text">The wheel collider is found under Physics components</p></div>
<p>After attaching the wheels I then attached an empty Game Object to the truck. To this object I added a wheel collider component.</p>
<p>The wheel collider is a component so it has to be added to a game object of some variety. I could have added it to my wheel mesh, but then I would not be able to rotate the wheel without rotating the collider.</p>
<p>As a component, the collider inherits the transform (position, rotation and scale) of the object it is attached to. By using an empty game object I am able to reposition align the collider without having to change any of the meshes.</p>
<p>Marc knows his stuff, so he created the truck and wheel meshes in the correct orientation. However if I had created the wheels using Unity&#8217;s  in-built cylinder object they would have started in the wrong orientation &#8211; they would have been lying flat on the ground and I would have to rotate them 90 degrees to stand them up. If I then attached a wheel collider directly to them the collider would inherit their transform and be pointing 90 degrees in the wrong direction.</p>
<p>Trust me, just attach them to an empty game object.</p>
<div id="attachment_85" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-85" title="wc_01_03" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/wc_01_03.jpg" alt="Wheel colliders in place" width="460" height="360" /><p class="wp-caption-text">Wheel colliders in place</p></div>
<div id="attachment_84" class="wp-caption alignleft" style="width: 216px"><img class="size-full wp-image-84" title="wc_01_02" src="http://carpe.com.au/slawia/wp-content/uploads/2009/08/wc_01_02.jpg" alt="The final object heirarchy" width="206" height="275" /><p class="wp-caption-text">The final object heirarchy</p></div>
<p>Here is the final object hierarchy. Truckbod has six wheel meshes and four wheel colliders attached.</p>
<p>I only added four wheel colliders because that is the number a vehicle will typically have, and I want to be able to use any scripts I write in future projects. Four colliders on the furthest front and back wheels should be fine for our truck as long as we keep the terrain pretty flat.</p>
<p>Finally I added a plane to act as the ground, and a light and camera to test the scene. I have not added any forces to the objects here, so left to their own devices they do not do much &#8211; the truck just sits on the perfectly level plane.</p>
<p>For the simplest of tests I rotated the plane to give it a slight downward slope. Then when the scene is run the truck trundles off down the slope &#8211; and eventually drives off the end.</p>
<p>That&#8217;s the end of part one. Next up is <a title="Part 2" href="http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-2/" target="_self">adding a motor and steering</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

