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:

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:

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.

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 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…

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.

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.