Unity

Come Home

Posted on by Quick Fingers in Unity | Leave a comment

A NEW IDEA

I’ve been contemplating posting this for over 6 weeks now. It was a project I started on December the 1st and finished on December the 14th of 2011. A new type of project for me, and something I believe to be fairly unique in the gaming world. It’s a pretty personal subject matter and the story is right there for everyone to see. No names or anything were used but the people involved are fully aware and have given the all clear for showcasing this online.

Come Home is an interactive true story based on moments in my life. It’s a PC/Mac Standalone game. It’s a fairly weighty download (around 75mb) and has some fairly heavy image effects so a fairly good GPU is recommended. If this isn’t enough to scare you off then go right ahead to the game page here

Boom Bugs Released!

Posted on by Quick Fingers in Boom Bugs, iPad, iPhone, Unity | 1 Comment

Title says it all :) Boom Bugs my physics based destruction game has officially been released on iPhone and Android, and the iPad HD edition is under review as we speak.

After working solo on the project for a little while I collaborated with the guys at Playerthree and between us we finished it from an early alpha to the polished game that it is now!

If you aren’t familiar with the game, please take a look at the trailer below (courtesy of unity3d.com)

All you have to do is head on over to www.playboombugs.com for more information, get it on your smartphones and start killing some spiders!

iPhone 4 Gyro Control in Unity

Posted on by Quick Fingers in iPhone, Unity | 11 Comments

The Write Up.

This idea spawned from seeing an iPhone app called Cameraman for Maya by Wes Mcdermott (www.the3dninja.com). The basic principle is you can use the gyro inside an iPhone 4 to record motion capture data. Really useful if you want to get an authentic shaky cam effect. I’ve been planning some larger projects in my head and figured something like this would be really useful for getting some animation clips for the camera in cutscenes.

Initially I thought this would be really easy in Unity. It has a remote iPhone app and I can just use that. I had a friendly peer-imposed deadline of 24 hours from Prime_31 so I figured why not :).

Unfortunately gyroscope support has only been added to Unity in the very latest version (3.4) and the remote hasn’t been updated to send Gyroscope data to Unity when using it as a remote. So that was out, (although that would also have limited me to having a usable system only on Mac). So I tried something else.

(If your not interested in the background and just want to get it going on your own projects, goto the bottom of the post to get the download links and how-to)

OSC?

For the uninitiated OSC stands for open sound control and is a messaging format optimized to be super fast over current networks. It’s primary use is in audio, controlling synthesizers and synchronising hardware with software. However due to its light weightness its really good for real time stuff, I did a quick search for iPhone apps that support OSC and found a BEAUTY. This is part 1 of the puzzle to get this thing running.

Control

The app is called control. It’s a single dev’s work by the name of Charlie Roberts (www.charlie-roberts.com/Control/). If it wasn’t for this I wouldn’t have made my 24 hour deadline. It’s basically a customizable interface allowing access to all sensor and touch events and send the raw data with OSC. The great thing about it is the interfaces are in JSON format so writing your own is a piece of cake. Oh yeah, and it’s free! Here’s an example interface for Control:

loadedInterfaceName = "template";
interfaceOrientation = "portrait";
 
pages = [[
{
    "name": "refresh",
    "type": "Button",
    "bounds": [.6, .9, .2, .1],
    "startingValue": 0,
    "isLocal": true,
    "mode": "contact",
    "ontouchstart": "interfaceManager.refreshInterface()",
    "stroke": "#aaa",
    "label": "refrsh",
},
]
];

So I made an interface that sends the gyroscope information 100 times a second and also has 4 triggerable buttons on the screens (used for movement in Unity). Once you’ve got all this sending data, it has to be received by something. So another app was required here. (Sending the gyro at 100hz was absolutely fine as long as my wireless signal was strong. Any sort of interference or low signal caused a few drops here and there)

Osculator

Another wonderful application that I utilised is Osculator (Mac only unfortunately. I didn’t search for a Windows alternative but OSC is an open format so should be plenty of software out there!). It is available as a demo which functions fully apart from a pause every 10 minutes or so for 20 seconds. This application receives all the OSC data you can throw at it then does whatever you want with it. You can see in the screenshots it provides these great live views for any parameters you send it so I get a nice graph showing me exactly whats happening with the gyroscope. On my osculator setup shown in the screenshot you can see I mapped each gyro output (pitch, roll and yaw) to a different joystick axis and then assigned the 4 on screen buttons to joystick buttons. Now just have to hook them up in the Unity editor and half the puzzle is solved.

Osculator Setup

Unity

Once we are in Unity we just set up the 3 axes in the Input Manager and write some script to handle it. The scripting is pretty straight forward. Just adding a little code to convert the axes into the transform data and everything starts moving around as it should. Initially when I did this I had the animation creation as a 2 step process where you would make your data whilst playing, then create the animation file and edit it after the game has ended and your back in editor. Now I’ve streamlined it thanks to Unitys AssetDatabase API I can create the animation asset whilst your playing and store it in your Assets folder. (This will obviously only work in the editor still, it wont work if you export. That was never my intention). Anyway that was the final hurdle so now, we are done :) It took me 20 hours in total to reasearch and complete the prototype.

 

Trying it Yourself!

If you’d like to give this a go yourself… Well, cool. But there’s a few prerequisites.

  • Control Application for iOS (iTunes Link)
  • Osculator for Mac. (Demo)
  • iOS with Gyro (iPhone 4 or iPad 2)
  • Your computer and iOS device on the same network.

Okay I have all that, I still wanna do this!

  • Start Osculator and grab my patch file from here. Load it and leave it running.
  • Start Control on your device: In the app, goto ‘Interfaces‘ click the plus (+). Point it at the URL http://www.quickfingers.net/unitygyro/layout.js (This will download the interface to your phone so it’ll always be there from now on) You should see it in the list as “Unity Controller“. Now goto ‘Destinations‘ and your computer’s IP address should be there, tap it. Then back to ‘Interfaces‘ and tap Unity Controller.
  • Inside Osculator you should see things starting to flash.
  • Now open a new or existing Unity Project
  • Download the GyroRecorder.cs file and attach it to the camera. (Or anything you want to record animation for)
  • Download the InputManager.asset file and overwrite the one in your projects /Library folder. (Be aware this will destroy your Input Managers settings so don’t do this on some pre existing project with complex button mapping setup).
  • Restart Unity.
  • With Control and Osculator running, hit play in Unity and everything should just work!
  • Hit ‘Zero‘ on the device to reset the current gyroscope position as 0,0,0.
  • If your getting weird behaviour and flipping make sure to lock your devices orientation. This uses Core Motion so the accelerometer does come into play. I had weird effects when the orientation was detected. It’s better to just lock it

The rest should be pretty straight forward! Hit the record button to start tracking input. If you stop the engine or press stop it’ll output to a .anim file in the Assets root directory. Okay enjoy!

Drop. Creative Mode

Posted on by Quick Fingers in Drop, Unity | Leave a comment

Here is a preview of what I’ve been working on for the last few days:

(I recommend full screen viewing)




So what is going on here? This is an extension of the sandbox mode in the current version of Drop. I’m calling it, creative mode. The idea of it is to give players total control of the tonality of each line, more freedom in placing objects, controlling the flow of start pipes and let them place behavioural objects as seen in the puzzle mode (like bouncy blue objects, and reacting yellow objects) and be able to tweak all parameters for them. All in all lots of tools to create some great sounds!
The Pièce de résistance is definitely the quantization that I’ve been working on (I turn it on at 1:34 in the video). This basically keeps all the hits in time. I’ve been playing with settings to try and get something that always sounds great, but obviously having strict timing means that thingswill be bound to a certain tempo. So I’m planning on having a slider control to dictate how tight you want the quantizing.

I’m still playing with buffer lengths and getting the ideal timings to allow the audio to play without hiccups and retaining sample accuracy. It’s just trial and error but right now it’s getting close to awesome.

The end goal is a service similar to Step/Net in Step Seq. Allowing players to share and rate others compositions. I learnt a lot from doing that before and I know there’s a few areas I need to tighten up. Namely not letting others just load your creation then reupload it as their own. This got on a few peoples nerves and rightly so. This time it wont be so easy to steal others work :)

The GUI has actually been pretty nice to me this time round. I’m using all built in UnityGUI stuff as I’m familiar with it, but stuff like sliders and radio buttons are all handled for me and I’m used to coding gui’s rather than designing them.

Hope you like it so far and I really hope you’re going to enjoy it and make some great sounds.

Drop. Post Mortem

Posted on by Quick Fingers in Drop, Unity | 3 Comments

Right time for another post mortem. Drop. has been fairly successful on Kongregate, Stabilising at around 4.08 rating which means its sitting in 2nd place in the Project Eden contest behind Step Seq. So altogether I’m pretty happy with how its been received. The future of Drop is an unknown right now, there’s a million ideas of what I want to do with it in my head, expansive composition elements, more focus on the music aspect… but for now as I’m hideously hung over, I thought I’d just write a post mortem of the first version instead. There’s a few interesting key things I’d like to go over how I did them.

physics

Arguably the most important aspect of the game, which was going to determine how the thing felt under your mouse, was the physics.


Now my first prototype of this project (which had a little youtube video about a month or so ago) used Unitys built in Nvidia Physx engine, constrained to 2 dimensions. Each line was a box collider and each drop a spherical rigidbody. Using the various physics material properties and rigidbody mass and drag settings I got a pretty good model of how I wanted it to feel. There was one quite major issue with this method though, and that is that Physx is non deterministic, there’s no way to make it fully deterministic as well, which means, two balls hitting exactly the same point on a line, with exactly the same velocity, may bounce in slightly different arcs.This essentially makes the game feel completely unfair as your balls will start deviating when your not doing anything. Bad bad user experience in a game like this. So, only one thing for it, write a really simplified physics engine from scratch with just the bare essentials to handle line/ball collisions. Nothing else was really needed and without the complexity of a full simulation the deviation from floating point rounding errors and such (which are prevalent in an advanced simulation such as using physx) are gotten rid of.

As I have a flash background (back in the days of actionscript 1) I’m quite used to not having luxuries such as physics libraries, I did a lot of this kind of thing, simplified vector maths and such. I remembered a set of tutorials from a guy called Tony Pa. (Essential reading for anyone interested in vector math Check it out here)So just using the bare minimum of what he describes here (handily open in my visual studio side by side with my code) I was able to get a ball line simulation running in a couple of hours with ease, and with no deviation! Once that was in place it was fairly easy to start adding properties to the lines I created such as bounciness.

So what about the solid objects? All I have in my simulation is Line/Ball collision, there’s no rigidbodies?

All the shapes (triangles, pipes, stars and boxes) were created in 3D as simple 2d polygons, then I use a script to parse the vertices of the 3d shape and convert them into lines which can be utilized by my quick physics engine. Then I just have boolean switchees to define if the object needs to be updated per frame (if it has any movement behaviours attached this is necessary) which just keeps the lines updated to the co-ordinates of the vertices. The only caveat which I’ve yet to explore is corners! This is evident as droplets can be fired inside objects if you hit right on corner. (Thankyou Kongregate users for the approximately 400 bug report e-mails detailing this fact with many screenshots!) I admit I knew about the ‘bug’ but kind of appreciated the effect it had, (it made really nice sounds after all) so decided it gave it character… possibly a bad call on my part but… Moving on!

the logo

 

 

 

The logo was a bit of fun, just making some nice little animation gave it a bit more character than a static image. So I made all the individual dots animate to there appropriate place. So how do they all know where they are going? Simple point cloud, manually edited. That’s it! As the name was simply Drop. I thought manually adding points wont take very long so just super imposed a grid in photoshop and copied the values into a script. Had it been called “Drop! – The Ambient Reflective Music Puzzle Game” I would of probably found a way to auto create the data :) Once I had all the positional data stored I just used Bob Berkebiles wonderful iTween with varying delays to make all the dots fall into place.

the audio

Given there is 12 notes in the scale, there’s quite a lot of audio bits, 36 in total for the hit sounds covering 3 octaves of plinky tones, I’m using the same logic as I used in Step Seq to pick the correct sound files for the key in which the level your playing is in. The theme tune is in the key of A as it’s alphabetically the first key and also the key of your first set of levels. The only clever bit really was in the drone pad. This was just the same sound file and I just adjusted the pitch by a certain amount to get it to the right key. However this had me confused for a while as I could hear the difference between a pitch value of 1 and 2 seemed like exactly one octave, so I thought well there’s 12 semi tones in an octave so each semi tone would be 1/12 pitch value right?
WRONG… all along its

float targetPitch = Mathf.Pow(2, semitones/12f);

So there, if you need to pitch shift by a certain number of semi tones, that line will save your life.

Level Structure

Right so making all those levels was actually really fun and only took 2 days, because of the great way Unity components are setup I was able to easily setup a really simple serialisation system that would serialize any properties of components I wanted. It was really simple I just had an abstract class called Serializable that looks like this

using System.Globalization;
using UnityEngine;
public abstract class Serializable : MonoBehaviour {
 
    public abstract string GetSerializedData();
    public abstract void SetSerializedData(string[] data, NumberFormatInfo nfi);
}

Then anything I want serializable, instead of extending MonoBehaviour, I just extend my Serializable class and implement the methods. As an example, here is my EasedMovement behaviour:

using System.Globalization;
using UnityEngine;
using System.Collections;
 
public class EasedMovement : Serializable {
 
    public Vector2 amount;
    public float duration;
 
    private Vector3 startPosition;
    private float time;
    private float oneOverDuration;
    private int direction;
 
    // Use this for initialization
    void Start() {
        direction = 1;
        oneOverDuration = 1f / duration;
        startPosition = transform.position;
    }
 
    // Update is called once per frame
    void FixedUpdate() {
        time += Time.deltaTime * 0.5f * oneOverDuration * direction;
        if (time >= 1f && direction == 1) direction = -1;
        if (time <= 0f && direction == -1) direction = 1;
        float newX = (amount.x != 0) ? Mathfx.Hermite(startPosition.x, startPosition.x + amount.x, time) : startPosition.x;
        float newY = (amount.y != 0) ? Mathfx.Hermite(startPosition.y, startPosition.y + amount.y, time) : startPosition.y;
        transform.position = new Vector2(newX, newY);
    }
 
    public override string GetSerializedData() {
        return amount.x + "," + amount.y + "," + duration;
    }
 
    public override void SetSerializedData(string[] data, NumberFormatInfo nfi) {
        amount = new Vector2(float.Parse(data[0], nfi), float.Parse(data[1], nfi));
        duration = float.Parse(data[2], nfi);
 
    }
}

You can ignore most of this, but pay attention to the GetSerializedData and SetSerializedData. Notice how Get just returns the values I want serialized and Set parses the values returned to it (always strings from a .txt file in my setup) and sets the variables up. This is it! Now thanks to my level saving and loading stuff (all very bespoke and messy so not posting ;) ) I can assign as many serializable components to every level object and all their individual datas will be stored, so I can just build my levels off of a few select prefabs, add components as I see fit and save to text format. (and obviously reload and make changes if necessary)

 

The end

I’m going to finish by saying thankyou for reading all this crap, most importantly thanks for playing the game (if you did!) If you haven’t played it yet head on over to drop.quickfingers.net to learn more!

Visual Studio, Unity and Mac

Posted on by Quick Fingers in General, Unity | 4 Comments

Well don’t those three look cosy up there together…

Many of you are probably Mac users, Unity started out being a Mac only product. Up until version 2.5 I believe. This goes some way to explaining why I’ve found in my experience with both that it is a more stable product on OS X. I admit it might be my particular PC but therein lies one of Apples strengths, there’s not many configurations they have to worry about so things generally work.

Anyway, since Unity appeared on Windows, there’s been some great work integrating Visual Studio and with Unity 3 onwards , using Visual Studio on a PC with Unity is completely seamless. As I switch between my desktop (PC) and laptop (Mac) frequently, it was annoying to lose the really tight integration because I was using a virtual machine on my Mac to run VS. So do as all developers do… if you can’t find a solution to a problem… fix it yourself!

Here is a video tutorial showing how you can get visual studio integrated nicely with Unity on a Mac using VMWare Fusion as my Windows host.

(The application I mention to convert a .BAT file to a .EXE file is available here.)

Drop. Is Live!

Posted on by Quick Fingers in Drop, Unity | Leave a comment

Hello my friends, a game I’ve been working on for the past few days has gone live!

It’s something I played around with a few weeks ago and made a little youtube video. But didn’t get round to working further on it until a few days ago, The idea is a synergy between physics and music, with a puzzle game built on top of it. I started to have so much fun making puzzles that it became the forefront and actually turned into a game rather than a toy. I was happy enough with the results that I have submitted it into the Kongregate Experience the Music competition.

So without further ado I would love you all to play it, and of course if you like it, every rating helps on the behemoth that is Kongregate.

Play it now!

For more information and some screenies visit the project page here.

I’ll probably write a post mortem on this one as there was a few interesting things that I went through during development that might be worth reading so stay tuned for that later on!

Peace!

Step Seq v1.1 – introducing Step Net

Posted on by Quick Fingers in Step Seq, Unity | 6 Comments

It’s been something I’ve been thinking about from the initial creation of Step-seq. An easy way for people to save, share and rate creations by others. On uploading to Kongregate I noticed they had a Shared Content API which was brilliant, with all the server work done for me but alas with no support for Unity… Also as I plan on releasing Step-seq for iPad and maybe other places I needed my own system. So here it is! I present Step/Net. (The slash is so it looks cool and techy)

Great… how do I use it?

I’m glad you asked! Let me explain. Every user has there own Step/Net area with room for 8 creations. (The reason I’ve limited it like this is to stop people spamming millions of versions of the same song every time they make a minor change).
From this window you can browse latest creations, highest rated, features, and organise your own collections that are accessible to everyone else.

From here you need to be logged into whatever service your playing the game on (Kongregate/GameCenter/Facebook/etc) to do saving and rating. So, if you are logged in, simply:

Uploading a Song

  • Make your song in Step-seq the usual way, add all the notes and pages you want.
  • Hit the Step/Net button
  • Hit the button labelled “Your Songs”.
  • Press the button labelled “Save Current Song to Step/Net”.
  • Type a name for your track and click “Save & Upload”.
  • It’s done! Your song will be viewable by anyone else who looks for it.

Rating other songs

Rating is even easier. When you click on a song from any list in Step/Net it will automatically load it and start playing… On the bottom of the screen you will see an info bar, and assuming you are not playing your own song, or are logged in, two buttons with a “+” and a “-” will be in the middle. Click + for songs you like and – for songs you don’t! Simples!

So get out and make some great songs, get your friends to rate them up so they can get in the highest rated… And I will regularly check some as featured songs so they will appear on the front page of Step/Net for all to see when they open it!