Math, Physics, Programming, Unity

Custom 2D Physics in Unity Using Verlet Integration

So 2017 will be my year of “doing the work,” a line I learned from Steven Pressfield in his excellent book named, unsurprisingly, “Do the Work.”  I’ve spent literally years reading about 3D math and physics and, outside of a few small demos I’ve experimented with and never released, I haven’t actually produced anything. I’ve also been inspired and motivated by a variety of books, most recently “Little Bets” which talks about innovators from Steve Jobs to Pixar and how they developed their craft. So, hopefully this year I can work on various smaller projects to hone my skills and really apply the knowledge I’ve gained.

To begin with, I’ve implemented a Verlet Integration based 2D physics engine in Unity, shown in the video above. I created this in basically 1 day over a weekend, and am pretty impressed with the initial results. To be fair, all the logic was taken from a C++ tutorial I found online,  A Verlet based approach for 2D game physics by Benedikt Bitterli, and basically what I did was re-implement it in C# and Unity. I’m no stranger to Verlet Integration, and did similar work many years ago in Flash after reading  Thomas Jakobsen’s breakthrough 2003 article, Advanced Character Physics.  So I very much understood the concepts already and could hit the ground running.

The idea was to begin with something small and achievable, and then build upon it. I started with 2D first, but it shouldn’t be that hard to expand the demo to support 3D as well. Eventually I’d like to explore GPU accelerated physics using Compute Shaders, but I do understand that’s a very complex proposition. Some of my earlier experiments with GPGPU programming were initially positive, but I quickly hit walls with the fundamentals of data structure and the huge can of worms of massively parallel computation. Still, I believe the potential is there, but I have a lot more to learn to harness that kind of power.

After my failed excursion in 3D engine programming, I’m a bit hesitant to make another series out of this. I do hope to continue exploring physics more, and will try to share what I can of the process as I move forward. Honestly, looking back at a lot of the games I’ve programmed in the past, I realized it was mostly the physics that made the games fun. Back then it was when Flash and 2D web games were big, so it was feasible to write the physics code by hand for each game. Today, with 3D being the norm, that kind of customized physics per-game is not tenable but, at the same time, I feel that many developers just use their engine of choice’s built-in physics and things haven’t really evolved.  I have some ideas I’d like to explore that just aren’t possible with what is on the market. Maybe the state of the art is just not there yet, or current hardware is not capable, but I feel compelled to at least try. If everything goes well maybe you will see more of these physics posts from me, and maybe something will come of it. Or, maybe not. I guess we will see.

Gaming, Review, Unity

Review: Getting Started with Unity 5 by Dr. Edward Lavieri


Getting Started with Unity 5 is mostly what it bills itself as: a way to get started in Unity for beginners. The book is clearly targeting beginners, and takes the reader from having never used Unity to making a simple farming-type game. I enjoyed reading it (in the whole 3 days it took to finish), however I’m not sure exactly how much I learned (if anything at all).

At 195 pages, the book is not extremely thorough, but does cover a lot of the basic fundamentals of game development with Unity. Unfortunately, that coverage is brief and only really scratches the surface. Some of the topics featured include: downloading Unity (an easy one), the editor views like scene/game/project/etc., game design, importing assets, animation, C# scripting, UI, and sound. Looking at that list, it seems like a lot of stuff, but some chapters are barely even 20 pages long. Not that it’s bad as an introduction, it could be a good place to start, but I feel for experienced developers the book falls short.

Besides the brevity of the coverage, I found some of the instructions confusing. For example, on the topic of programming, the author explains how to code different animals in a farm to do similar things like eat or have babies. This would seem like a classic text-book example for using object-oriented programming principles. Instead, the author concocts some cryptic array of numbers, where a 0 means a pig and a 1 a chicken or something or another. Not to say that this won’t work, sure, it will compile. It’s just not a great way to teach programming concepts to a beginner.

I don’t especially like giving bad reviews, and I don’t want to say the book is bad. It’s titled as a “getting started” book and that’s just what it is. I’m just not sure it’s the best instruction for a beginner, and the programming sections in particular were lacking for me. There are not many Unity 5 specific books available today but, truthfully, much of what’s covered in this book would have worked the same in Unity 4. Even so, the older Unity books I’ve read were much more comprehensive and useful than this one. So if you’ve just started to learn now, this book may be worth picking up as a quick intro if you understand it’s not very deep at all. Experienced Unity developers should keep moving.

Gaming, Kickstarter, Sci-fi, Unity, Virtual Reality

This is Cyberpunk: TECHNOLUST Kickstarter Campaign Live

technolustNow this is my kind of game: a cyberpunk first-person adventure set in a dystopian future. Native Oculus Rift support. A NSFW TRON poster (though I bet they will take that out). This just looks too awesome for words. I backed the Kickstarter for $50 bucks, but I’m willing to up the ante later in the campaign if necessary. Really anyone with an Oculus Rift, or that plans to buy a Rift, should throw some money down on this project. Of all the things I’ve played in VR, I think this is my favorite. And I’ve played a LOT. Get on this.

Gaming, Review, Unity

Review: Learning C# by Developing Games with Unity 3D Beginner’s Guide

Learning C# with Unity

Honestly I’m not sure why I bothered with this book. It’s not that it was a bad read per se, but it’s really for stark beginners. Learning C# by Developing Games with Unity 3D by Terry Norton is really for people that have little or no experience with programming. Meaning if you don’t know what a ‘variable’ or a ‘method’ is then this book will probably be helpful. It’s really intended for artists using Unity who want to add some scripting skill to their knowledge. If you are already a capable programmer (in C# or not) then this book will probably not be that helpful.

Personally I’ve been programming in many languages for years, however I’ve only really dabbled with C#. So I figured this book could be a good refresher. Unfortunately it is on such a basic level that it doesn’t really cover the features that make C# unique. If you have any programming experience the text will seem remedial. Some of the topics in the book include: variables, functions/methods, classes, and dot syntax. The main example project covers creating a state machine to handle switching between different screens. In actuality, this is a good introduction to programming though it doesn’t teach you nearly enough to be able to start creating a complete game in Unity. However, it is called a ‘beginner’s guide’ so it’s not like it was mislabeled.

Learning C# by Developing Games with Unity 3D comes in at just under 300 pages, so it is not a long read. I think I finished it up in less than a week. So I’m not terribly upset about taking my time to check this out. To the book’s credit, I did learn one new trick: how to have a component act as a singleton, so I did gain something. I do think if you are an artist with no previous programming knowledge, this could be a great intro into the field. However, to get anything serious done you will still need some other books to take you to the next level. Overall not a bad book, but if you’ve already be coding for any period of time you can probably skip it.