Exporting a sprite sheet from Flash into Unity animation

I didn’t even realise Unity had an animation timeline until recently, in my Space Turd project I used scripts to time things appearing on screen – when actually I could have made it easier for myself by using tweened animations, something I love in Flash.

Flash is still my favourite tool for drawing and animation though, so for this new project (which currently I’m just calling “Glob”) I wanted to animate the character of Glob to blink and look from left to right.

So I animated this in Flash, and I was happy with it. It’s so nice to use Flash’s timeline again, it’s been too long! And it’s super easy!

timeline in flash

Now to move this into Unity

I thought this bit would be where it gets difficult. What I didn’t know until recently though is that you can export a spritesheet from Flash, which is more of an industry standard for games. It puts all your animation onto one image.

If you right click the movie clip containing the animation you can select “Generate sprite sheet”, which exports a file like this:

glob eye spritesheet

You might not be able to see the white above, as the background is transparent.

Then in Unity you can load this as a sprite (putting it into a folder called “Sprites” automatically converts it. Then you have to tell Unity how to split this file up into it’s different frames.

First I selected “Automatic” but it for some reason wanted to merge the first 2 frames, so had to select the 2nd manually. Which wasn’t difficult, just making sure it’s the same width and height as the others.

Animation in Unity

So I opened the animation window, and got a familiar timeline. It looks similar to Flash but works probably more like animation in 3DsMAX. There’s a record button, and changing any property of the object is recorded. So I dragged it to 30 seconds, swapped the sprite for the “blinking” frame, and saved it.

unity timeline

Unity creates an Animation file which saves in your project. It also saves an “Animator” file. Not sure what this is yet, but I deleted it and the entire animation was deleted, so it’s essential! Here’s the contents:

animator I’ll post more info about this “Glob” project here. But in the meantime, here’s the repo on GitHub.

Some notes on exporting Unity to Android on Windows

I’m experimenting with exporting my latest Unity project. I’ve not blogged about it yet, but it’s a super simple game. After the mammoth last one, I thought I’d do something short this time.

Installing the Android SDK

There’s no native export from Unity to Android. It’d be nice if there was, but I think I expect too much sometimes! So you have to install the Android SDK, which is easy, they give you a link straight to the site. But before you install that, you need to install the Java Developer tools (JDK) – the whole thing feels like one of those Dizzy adventures where to finish one quest you have to do another beforehand. Continue reading Some notes on exporting Unity to Android on Windows

Version 1.0.2 of mega turd

I’ve uploaded new Mac & Windows versions of Attack of the mega turd. Including an arrow pointing to the enemy on level 1 (not the escape levels). You can download them here: http://www.indiedb.com/games/attack-of-the-mega-turd-from-space/downloads

The process was fairly mundane, although I’m glad Inno (the Windows packager) just got on with it and used all the same settings as last time, making it nice and easy! I should have used a Mac packager too, but apparently this can only be done on a Mac.

Maths problems are the worst, and how I added a pointer arrow to a moving target

The biggest criticism of my recent game (other than it being a shit game about shit) was that it was difficult to find the enemy turd in level 1.

I thought that the best solution for this would be to add an arrow pointing in the direction of the enemy, to follow. I’ve seen this in so many games that I assumed it would be dead easy to add. Something like this:

arrow to target

Turns out I was wrong.

Or maybe it’d be easy if I was better at mathematics. But for me this was a hard one to solve. Knowing that my grasp of maths is worse than the average gym instructor, I trawled the internet for help. Luckily Unity’s community is large and this question has been asked many times. However every answer I found seemed to be lacking something, and wouldn’t work for me. Possibly because I was adding my arrow to the UI layer (and I’m not changing that because it’s sensible. Sensible goddammit!) meaning that the axis is different – my gameObjects rotate on the y-axis, but I wanted the arrow to rotate on its z-axis.

Anyway, despite spending a lot of time in Unity Answers, and posting the question twice but slightly differently worded (I was getting desperate) it was a Facebook comment where I got a good link to a solution. Here’s the solved formula:

//--point arrow to enemy
var dir = transform.position - target.transform.position;
var angle = Mathf.Atan2(dir.z, dir.x) * Mathf.Rad2Deg;
arrow.transform.rotation = Quaternion.AngleAxis(angle+90, Vector3.forward);

So thanks Regan No, and the link he sent: http://answers.unity3d.com/questions/654222/make-sprite-look-at-vector2-in-unity-2d-1.html

This means I can rotate the arrow around the center of the screen. Now quite attached to the edge, like I wanted. But good enough!

Making the arrow hide when close to the enemy

I wanted to hide the arrow when it got too close, as it’s then useless. So faded it out. Here’s the full script (or see it on GitHub):

var target : GameObject; // GameObject to point to
var arrow : GameObject;
private var angle : float;
var fadeSpeed : float = .05;
var amt : float = 0;
var distanceToTarget : float;

function Start() {
   arrow.GetComponent.<CanvasGroup>().alpha = 0;
}

function Update() {
   //--point arrow to enemy
   var dir = transform.position - target.transform.position;
   var angle = Mathf.Atan2(dir.z, dir.x) * Mathf.Rad2Deg;
   arrow.transform.rotation = Quaternion.AngleAxis(angle+90,    Vector3.forward);

   //--get distance
   distanceToTarget = Vector3.Distance(transform.position, target.transform.position);

   if(distanceToTarget < 4.5){
      //--fade out
      if(amt > 0){
         amt -= fadeSpeed;
      }
   } else {
      //--fade in
      if(amt < 1){
         amt += fadeSpeed;
      }
   }

   arrow.GetComponent.<CanvasGroup>().alpha = amt;
}

You can download this game on IndieDB.

The 1st review of Mega turd

poo2

So I published my game Attack of the mega turd from space 2 weeks ago. I didn’t make a big deal about it, as I was mostly too embarrassed to show anyone, but it did get 1 review on Newgrounds:

Well, a pretty nice game you’ve made. The graphic just looks fine, no need to add more (would just lead to lags on older PCs). But the steering … much room for improvements. The chosen controls are a good way to control something from a FPV. but used in a top-down view it just leads to frustration. I would recommend using a classical coordinate system control instead of thrust+direction.
that, and a mini map, and you have a really cool game.

Okay that isn’t the worst review, and I’m happy that this person liked the graphics, as I spend too long obsessing over them – even though I know they’re not great!

game start screen
More about the game

They have a problem with the steering, and I can understand why. It drifts a lot, and testing the game over the last few months has made me not really notice it too much! I actually quite like how it handles, but agree it should turn a bit tighter.

In the future I think I’ll move to a mouse control system for desktop though, it just seems too alien these days to switch to keyboard to play this sort of game.

I’ve finished a game but too embarrassed to show it anyone because it’s about a giant turd

So this is my 3rd game made in Unity. I chose a silly subject so that I could be experimental without getting too serious about the project. Unfortunately though it’s taken me AGES to finish and I’ve put quite a bit of effort in (see my other post “I’m literally polishing a turd”).

game start screen

I said in my last article that the last 10% takes 90% of the time, and it definitely felt like that for this project. Doing simple things to finish the game has taken a long time. The intro, the message at the end when you complete the game, and the start menu, all took far longer than I was expecting. And tbh it’s irritated me how difficult those things are to do in Unity compared to Flash (which I used to use to make games – although that was many years ago), although this could just be my imagination and I’m looking back with rose tinted glasses, but I did seem to make progress faster in Flash, despite it’s flaws, (and everyone I know giving it a lot of hate these days).

Play the game!

poo2Okay so if you do what to play this game, you can play it in the browser on Newgrounds.com here.

(It has to be Firefox tho, as Chrome has killed the Unity plugin. Grr!)

I also made a downloadable windows version as many people won’t have Firefox. I’m quite pleased with this because I used free software called Inno which creates an installer.

Download the windows version from IndieDb here.

Download the Mac version from IndieDb here.

 

Intro & end screen

So I wanted to show text in sequence, and the user can page through these by clicking. Simple right? Sounds easy right? I can write a script that does that by putting the text in an array, or at least a reference to the UI text on screen, and hide/show them when needed. And another script to fade the text in/out. Problem is I don’t have the patience to do all this manually on Unity script. It should be a solved problem! It’s actually be easier to do this in HTML, and whenever I start thinking stuff like that, I panic. Then start thinking I’m doing the entire project wrong and I should be doing it differently. Then I get into a sort of spiral which sends me crazy.

I end up thinking a bit too long about stuff when I should just be getting it done. Like this…
image

Anyway I settled on unhiding text in sequence for the intro (couldn’t be bothered to fade it), and a movie credits style scrolling text for the intro which was easier than mucking about with timing text to come on at the right moment, or clicking through with the mouse. That’s sort of thing would be easier in Flash, but I had to put that out of my mind or I’d go crazy and want to start the entire project over!

Making it reusable and open-source

Most of these scripts will be reusable in other projects. I’ve even put them on github in a public repo in case anyone else can make use of it.

player
SEE ALSO: I’m literally polishing a turd

But mostly that’s just a handy and searchable place for me to keep it backed up!

Anyway I’ve learned a lot. Here’s what I’ve focussed on:

  • Unity’s canvas UI items, and hiding/showing panels.
  • Fading the screen in/out
  • Loading new levels & initialising them (I might do this differently next time though)
  • Loading dynamic elements from resources
  • Sound effects and music, and changing the music on the fly.

I’m glad to finish this project and move on to the next idea!

Oh btw, I got a review – Yes ONE REVIEW! See it here.

I’m literally polishing a turd

I’ve been trying to finish my latest Unity game, the one I mentioned at the end of a recent article (see here), and which I’ve been posting updates on IndieDB (see here).

It’s just a silly game, I’ve been creating for the purpose of learning new stuff, making sure that every script I write can be reused in other projects, so eventually I can have a toolkit ready to go, to make progress much quicker.

It’s been almost done for ages now, but…

The last 10% takes 90% of the time.

Or at least that’s what it feels like.

I want to get this project finished so I can move on to a cooler, less stupid game. One maybe worthy of putting on Steam greenlight. But I don’t like making anything that isn’t at least finished. I’ll be putting this onto Newgrounds, for some people to play, although the Unity plugin doesn’t work in Chrome any more, so its audience is limited.

turd

Don’t get me wrong, this won’t be a super polished game, but things that end up taking a long time are those little bugs you notice, I had one problem where the player gets stuck on a particular bit of terrain, and I spent ages tweaking the drag/mass/velocity values of the ridigbody.

And sound.

Sound DEFINITELY takes a long time.

In fact it didn’t take me long to find the background music, there’s loads of great royalty free stuff on Newgrounds you can just use as long as you credit. Oh that’s another thing I have to do, create a panel on the menu for addign credits. Dammit, UI stuff in Unity takes a lot longer than in just HTML/CSS.

I wanted a bit in my game where the background music changes when the user enters a certain area. Just little tweaks like that is the sort of thing that takes a long time.

Another thing I added is a screen that flashes up to show the keyboard controls, as I realised it wasn’t obvious at all which keys were used. That’s something else that takes time. Hopefully though the script I created for that will be reusable in another project.

Controls

I admit I did get carried away adding stuff to this project that I didn’t intend to at the start. I’ve added turrets, something that actually didn’t take too long, but is an additional extra I didn’t plan for.

turrets

And making turrets target the player and fire took me at least 3 evenings because it involved maths (not my strong point) and because 3D is harder than 2D! The turret is above the player, so it has to angle down and shoot, which would look much better (I think) in 2D.

I do wonder if working in 3D has slowed me down. I’m sure all those crappy Flash games I made at Uni didn’t take this long!

There’s also things that I haven’t managed to do, even though I’ve spent a lot of time on. I really wanted an arrow pointing to a target off-screen, like this…

arrow to target

But it’s just too difficult for me right now. Maybe for another project.

So anyway, I’d better wrap this up and stick it on Newgrounds asap.

Chrome pulls Unity plugin

I spent a long time mulling over which game framework to learn, and the biggest benefit of Unity was it’s export options to so many platforms. I’ve always enjoyed making web games, something quick and easy to play, which loads right in the browser, so I can easily show people by sending them a link or putting it straight on Facebook.

It’s so much easier doing that than asking for someone to download an executable file, which always seems like a big ask, or on a mobile to go to the app store (and the inevitable problem of being in ALL app stores, so that people aren’t excluded), and downloading, making sure they have enough space on their device etc etc, that all seems like a ballache compared to flinging someone a link to see what they think of the half-finished thing.

So Unity did still have that benefit. I could add a crappy game, half finished and buggy to Newgrounds, to see what people thought, and they didn’t have to do much (okay I suppose they had to have the plugin, but that’s only the same as Flash player for Flash games).

Chrome has now killed the Unity plugin

Which means it’s less easy to show a WIP, or a small game that only took a few days to make without the rigmarole of having to download it.

I’m hoping the time I invested in learning Unity wasn’t wasted, because it still is an awesome tool for exporting to Android and other platforms (although I haven’t made anything decent enough to distribute yet).

It’s not all bad, it looks like Unity has a way to export to WebGL, which means it should work in the browser WITHOUT even needing a plugin, which is even better. I just haven’t experimented with that yet.

But I probably will!

The image at the top of this post was created by someone who I think is quite pissed off about it. I got it here

My 1st & 2nd games built in Unity

I’ve been spending a lot of my spare time recently creating a Unity 3D game. I’m still very much a beginner at the platform, and each game I work on feels like the first. I’m still learning, but getting faster with each project.

The latest project has taken me months already, fitting it in around work and other commitments.

But I’m not going to write anything about that yet (okay that’s a lie, I’ve written plenty about that over on IndieDB already – click here), because I haven’t yet blogged about the games I created first.

The 1st game – ReTardis

Because I was a total beginner, I started on a ridiculous project that wasn’t to be taken seriously at all (hmm, that sounds familiar, this applies to my 2nd & 3rd attempts too!).

I did add it to Newgrounds though, you can play it in the browser – click here.

The 2nd game – Starbug Thruster

Starring the spaceship from Red Dwarf, one of my favourite comedies as a teenager, this game was based on the physics used in my previous game, but simplified for mobile touch interface. You only have to touch the left or right of the screen to thrust up and in a direction.

I loved making this game, and based the story around Blue Dwarf, the text-based game I created many years ago, and which people still play (because it’s awesome, and the most rewarding game you can play).

I spent some time creating it for mobile, although abandoned that idea when I realised using a spaceship which is someone else’s IP isn’t a good idea. I might bring back the idea in a future game though. You can play this in the browser on the Newgrounds website – click here.

starbug thrusting starbug thruster hitting overhead beams Starbug thruster screenshot, knocking over boxes

The 3rd game – Attack of the mega turd from space

Yes. You read that correctly. This is another ridiculous game. It’s so ridiculous I wrote about it how ridiculous it is here.

Intended to be another silly learning experience, I’ve actually been putting a lot of effort into this game. And I’ve been learning a LOT. I think my next Unity project will be a lot quicker, as I now actually know what I’m doing.

Here’s a sneak peak of the progress:

progress of attack of the turd from space

Okay that screenshot doesn’t actually feature a turd. But there’s more to this game than the title.

I’ll be posting more progress and screenshots on IndieDB – click here.