Something fun – Learning the new Unity 4.6 GUI

It’s all about doing something fun to get motivated – so here I am with the tutorials for the new GUI system in Unity3d 4.6 (about time guys).

Each new UI element resides on top of a ‘canvas’ element. If you add an element with a parent ‘canvas’, one will be created for you. You can have more than one canvas in a scene.

There are a couple of render modes for the Canvas:

  • Screen Space Overlay (will autoresize and is applied to the display size)
  • Screen Space Camera (will autoresize and is applied to the camera view)
  • World Space (Will NOT autoresize but can be placed anywhere in the scene)

You can add elements and adjust their position using the ‘Rect Transform’ – there is also a new ‘Rect Transform’ tool in the toolbar.

Posted in 366 Day Method, Design, Unity | Tagged , | Leave a comment

Ready to start afresh.

Okay so I finally have my own space in London, I’ve built a new PC to work on and picked up a 22″ TV as a monitor.

I’m good to go.

Just updated my tablet drivers so I can start sketching (which work fine on Windows 10 fortunately). I’m working on the concept art based upon some work an artist has done for me. It’s not quite there yet so I’ll see if I can give some notes to coax it out of them.

I’m going to work on the Title Card and initial UI. That way I’ll get a feeling for the direction of the art style and also get practice with Unity3d’s new GUI update.

 

Posted in 366 Day Method, Design | Leave a comment

Procedural pop-up

So I’ve gotten the mole popup working.

The scene is built using two tags – hidden and unhidden. The ground of the prototype scene starts as unhidden and all the moles start as hidden.

First we need to try and trigger a random mole coming up each time. So we’ll start tracking down an unhidden object – which will always be the ground to start with. The action ‘Get Random Object’ looks for any object with the ‘unhidden’ tag. This item is stored. Next we look for the nearest hidden object using the ‘Find Closest’ and store that variable.

The object that is hidden is then made visible with the ‘Set Visibility’, then ‘Set Tag’ can change it to unhidden (so it doesn’t get chosen during in the next loop). Finally we can animate our mole’s pop-up with a quick ‘iTween Move By’.

The loop is wrapped up with a ‘Wait’ action before going again. Each time it loops it will find a hidden mole, unhide him, pop him up and go again.

stackamole1.0

Next we need to get the interaction working.

Posted in 366 Day Method, Playmaker, StackAMole, Unity | Leave a comment

Popped out of nowhere.

I was passing time at work today and a quick casual game came to me. it uses the idea of whack a mole but takes away the score timer. It should be really quick to make so I’m going to see if I can knock it out as a practice exercise.

It uses Unity 2D so I need to setup Playmaker to be 2D friendly – the addon section of Hutong’s website has the unity file I need.

I think I can make the game loop almost all procedural – which should save time. I’ll write more when I have the first section working – the popup of the moles.

Posted in Playmaker, StackAMole, Unity | Leave a comment

(10) The Paint Prototype – Feels wasted.

I’ve been working on sketches to draw up the art assets. After a bit of use in paint I realised that without layers or alpha – I couldn’t really do anything useful in the package. So on to Photoshop. By the time I got it all installed the night was over.

I spent the time looking at Playmaker Actions as it installed – the more I know what parts I can use – the more complex I can make the state machine.

Posted in NPC, Unity | Leave a comment

(9) The Paint Prototype – Feel the pain

Time to fight – albeit one sided.

Today I’ve completed the hero’s damage giving behaviour. The hero can now kill the enemy. I also setup spawning to test multiple battles in one playtest.

First we need getters and setters to communicate the variable changes between the two objects. This is safer and more controlled than using public (global) variables.

So to the wait state I’ve added two ‘Get FSM Float’ actions that will get the gameobject that was collided with and seek out the FSM that contains the EnemyHealth variable, and the EnemyDefence variable. Both of these variables are stored locally on this FSM using the same variable names. That is the getters setup, after fighting we can use some setters.

Diving back over to where we left off yesterday, lets calculate the damage on our ‘NormalDamage’ state. Here we use a ‘Float Operator’ action so we can store the result (PlayerAttack – EnemyDefence) as a new variable called ‘DamageGiven’ – in code it would be:

var DamageGiven:float;

DamageGiven = (PlayerAttack – EnemyDefence);

Next it uses a ‘Float Subtract’ action (EnemyHealth – DamageGiven) which uses itself to do the calculation – in code it would be :

EnemyHealth -= (EnemyHealth – DamageGiven);

Now we can add the final piece of the puzzle; the setter. For this we use ‘Set FSM Float’ action. Like the getter but in reverse we use the gameObject that was collided with and stored as a variable. Choose its EnemyVitality FSM and drill down to the EnemyHealth variable.

This is our damage sequence set. For our ‘CriticalDamage’ state we just have an added ‘Float Multiply’ action which double the damage before affecting the enemy health.

In the same way that the enemies FSM is constantly checking if it has zero health (and dies) we now need to complete the hero loop by checking if the enemy is still alive. A quick ‘Float Compare’ action which checks against zero health on the EnemyHealth variable is enough. If it is higher is loops back to the ‘Wait’ state and the hero will strike again, if not we can loop back to the ‘WalkingRight’ state.

We are all good to go – playtesting the hero cube will wander over, batter the enemy repeatedly until he has no health and gets destroyed, then he’ll walk on.

FSM_1.3

As a final piece I’ve setup some spawning which is super easy with PlayMaker. On the camera I’ve created a a Spawn FSM with ‘Get Mouse Button Up’ actions for left and right click – these transition to one state for ‘SpawningHero’ and one for ‘SpawningEnemy’. Both of these have a ‘CreateObject’ action which uses a prefab for the instance gameobject and a reference to an empty gameobject in the scene as the spawn location.

Now clicking will create more heroes or enemies if I need them.

So next I need the enemy to fight back, although I’m tempted to work on some terrible art assets in MS Paint – I’ll see how the next day takes me!

Posted in NPC, Unity | Leave a comment

(8) The Paint Prototype – Did you miss me?

Okay so I’m working on the hit behaviour today. We need to figure out if a hit is successful or not.

Once the collider triggers against an enemy we can start our fight behaviour. First we have a wait state – this is run by the HeroSpeed variable. We can set the state length in seconds using a wait action.

Next we plug in our HitCheck state, here we create a percentage check with a ‘Random Float’ action and store it as out HitRoll variable. We can then check for a miss using a ‘FloatCompare’ action that will check if the roll is less than out ‘MissPercentage’ variable (set at 10%). If it is less then it will loop back round to the wait state and try again. If higher it will move onto the ‘CriticalHitCheck’.

The ‘CriticalHitCheck’ uses the same float compare as the miss, but this checks against the original roll (doesnt reroll) and if it is higher then the CriticalHitPercentage (currently 90) then we can go to the ‘CriticalDamage’ state, if not then the ‘NormalDamage’ state will take over.

If we run the process now the hero will walk along until he hits an enemy. He will then roll a random number between 0-100. If it 0-10 he misses and will wait a couple of seconds and try again. 10-90 will lead to a normal strike and 90-100 will lead to a critical strike.

FSM_1.2

Posted in NPC, Unity | Leave a comment

(7) The Paint Prototype – Enemy Mind

This is a bit more complex. I’m going to build an enemy that interacts with the hero.

For his behaviour I’ve setup an new FSM that deals only with vitality. This will monitor the current health, max health, min health (death) and moral. Using a ‘float clamp’ we can setup the current health as the variable, max-health as the max number and 0 as the minimum.

Then with another ‘float compare’ we can look to see if the health has reached ‘0’. If so we move to the dying state which will destroy itself.

Next we can work on setting up the attack.

Posted in NPC, Unity | Leave a comment

(6) The Paint Prototype – Making enemies.

So until we get our sprites made we are using surrogate geometry. A diamond will make up our bad guy.

We need to manage control over the tags as they will decide our collision interactions. To make sure our hero ignores the enemies on the way back to ‘base’ we can set the tag change when he hits the barrier. We also want a tag change when the hero and enemy are fighting so that they are allowed to fight alone. I’ve setup tags for ‘retreating’ and ‘fighting’.

I’ve also started setting up the Hero variables PlayerHealth, PlayerAttack, PlayerDefence, PlayerGold, PlayerMoral. These will be used during the fight.

For now the trigger is setup so that the fight state will start on a collision with the enemey, the tag will change to fighting and a tween animation will start.

Posted in NPC, Unity | Leave a comment

(5) The Paint Prototype – What version is this?

Time to setup some version control. The free version of Unity3D now allows users to setup version control. The first thing to do is to go to:

Edit>*Project Settings>Editor

and under ‘Version Controls’ turn on ‘Visible Meta Data’.

Next install Mercurial and open up terminal / command prompt. Go to your project root folder and type:

hg init

This will create the repo folder ‘.hg’.

Grab a text editor and type the following for an unwanted file list:

syntax: glob

 

Library

Temp

 

*.pidb

*.sln

*.userprefs

*.csprog

 

*.orig

 

Save it as ‘.hgignore’ in the root of the project also.

Now we can add files to the repo. Type:

hg add

hg commit -u myname -m “My comment like initial commit”

 

And that should be that! hg add pushes all files for the commit. hg commit logs the username and commit message.

Some additional commands are

hg help (command list)

hg help command (help for the chosen command)

hg log (check the commit log)

hg status (status of files)

hg revert -r 0 -a –no-backup (to revert where -r is the revision number from the log, -a is everything and dont create backups)

hg rollback (undoes your last commit)

hg add myfile.txt (pushes a specific file before you commit)

Posted in NPC, Unity | Leave a comment