Unity5 Development Diary

Unity5 Development Diary

Thursday Dec 21

I’ve been investigating lots of level design tools and I found one that seems to work really well.  its got subtractive features as well as additive and is pretty mature.  I made a few videos about how to use it although they aren’t edited yet and aren’t uploaded.  Its called SabreCSG.  These should let me make larger levels for Super BelDevere which is what I’ll be working on today: making a large level for that game.

I’ve been having a problem for a while where the ball sticks to the wall no matter how I adjust the bounciness in the physics materials.  I found out that in the physics engine there is a bounciness threshold and below that threshold of speed  in the same linear direction as the wall then those things don’t bounce.  I changed that bounciness threshold to be 0 so lets see how it works … Yup that worked great.  I tested it with a higher number (20) just so I could understand what was going on and it made the game unplayable (just as I suspected).

Monday Dec 11

I have been working a lot on my pong style game called Co-Parenting Beldevere.  In this game Beldevere feels unloved by his deadbeat father so as his mother you have to play both roles (control both paddles) to help BelDevere feel loved.

Co-Parenting Beldevere
Co-Parenting Beldevere

Cut Scene

I spent a lot of time over the last few days working on a simple cut-scene.  When I think about how apparently complicated the cut-scene is I feel like it took me way to long to figure out how to do this part.  Thats just me getting judgmental towards myself but there it is!?!  The more cut-scenes and similar animations I make the better I will get at it. Also I feel like it will be valuable having done it this more difficult way because when I see tools or scripts that make this process easier I will have a point of reference and I will be able to understand the problems they are trying to solve and the advantages to the way they chose to solve them.

Physics

I have had a lot of trouble with the physics in this game.  I’m beating myself up about this a bit too because it seems like they should be so simple, and it was simple to get it working somewhat, but to add convincing English to the ball and to make it feel good was anything but.  The problems were manifold.  Sometimes the ball would get stuck.  Sometimes the English wouldn’t work at all.  My solution as of today feels fantastic and involves adding a shallow sphere collider to the paddles.

Saturday December 2

I went to see my friend Chad Carrie yesterday and he showed me some great ways to use Sketch-Up to make 3D models and import them in.  Here is some of what I learned:

Tuesday November 28

Today I made a 3 part tutorial (Part 1, Part 2, Part 3) about converting your game into stereoscopic for iOS.  There is a lot of important information in these videos about how I pulled this off, but keep in mind that there have been quirky problems (which have apparently nothing to do with the stereoscopic display and work perfect testing on PC before I move it over to iOS)  each time I’ve done it.

Monday November 27

Beldevere in Stereoscopic 3D on Sunday November 28!

Stereoscopic Beldevere
Stereoscopic Beldevere

Marshall and me worked on getting an in game stereoscopic display working for like 4 hours on Saturday night.  We actually got that part working ok pretty quick but then (and I saw this coming) needed to get some form of external control (you can’t touch the screen when the phone is in the VR Goggles.  We eventually gave up at like midnight, but I obsessed about it and found something that night and implemented it the next morning that *mostly* worked.  I was able to tighten it up over the course of the day and show Marshall and his friend and my beautiful encouraging wife Cristi Level 3 of Beldevere in 3D later that night!

Later on that evening I was able to get controls working for all levels as well as the title screen and high score screen and while there are two outstanding bugs it does work and I genericized the stereoscopic camera and UI canvases such that all of my levels benefitted automatically and now you just click a button in the inspector and that level is Stereoscopic 3D!  Its funny how time flies because its just Monday right now but it feels like its been an eternity since that happened.

I also ordered a nice gaming PC on Black Friday which will be here perhaps later tonight and I just picked up a nice monitor from Best Buy (Cyber Monday Sale).

Monday November 20

Yesterday I tightened up some of the code for expanding and shrinking objects.  Today I totally re-worked level 2 scaling it to 1.5x its previous size (x and z) and adding bounding volumes so you can kind of ride the walls a bit.

Yesterday I also experimented with using the terrain features of Unity to make a level 1.  I liked it a lot, however it totally “showed up” the rest of the levels.   At some point I will need to draw the line and say its good enough to ship and if that level looks way smoother than the rest I will feel like I need to make similar changes to all of the rest of the levels to make them catch up to that one.  I’m struggling with where to draw that line.

Saturday November 18

Today I’ve been working with lighting, adjusting it, balancing it, getting all the levels balanced, trying to not wash things out, etc.  I noticed that on mobile especially some things looked weird, even dark.  I started by re-baking all of the lighting for all of the levels, then I worked with the skybox and the default ambient light color making it a light grey. Then I made the directional light a darker gray and adjusted its intensity until it looked about right and that seemed to work out pretty well for all of the levels.

I found a problem with shadows and spent most of the day finding a workaround.   (details in my article on iOS)

Shadow Distance Differences (iOS Build Setting)
Shadow Distance Differences (iOS Build Setting)

Tuesday November 14

Yesterday was really monumental but today I got the controls working on the iPhone!  Just one more thing to do and it will be fully functional on iPhone.  I feel like parts are still “clunky” but it will be a minimum viable product as the saying goes.

Monday November 13

I got my game building and running on iPhone today!  *Huge Milestone!!!*

Sunday October 29

Wow so much progress!  I got sound throughout and really … its a REAL GAME as of just now!  5:00pm sharp.

It starts with a musically backed title screen, moves into a musically backed level with lots of fun sound effects, and when you are done with that it moves into a musically backed high score screen and then back to the level select screen!  I’m so proud!

Thursday October 26

I travelled to see my dad last week and got some good feedback and ideas from him and my mom.  Thanks guys!  I got the skeleton of my new much more interesting scoring system working as well as having fixed a problem I made with the gravity collector.  I got it working on one level but it broke the rest.  It wasn’t a difficult fix.  This week I’ve been working on sounds and music.

Saturday October 14

Got the Gravity Collector working much better.  Occasionally it used to leave dots stranded on accident but it doesn’t do that anymore.  A fun side effect is it ends up swirling the dots around the player and sometimes getting pretty close to a perfect zero gravity orbit (illustrated in the video below) a situation which I’ve cleaned up now but which was cool enough to make a video out of..

Unity5 C# code for gravity collector
Unity5 C# code for gravity collector

Friday October 13

I found out about NavMeshAgents priority field and how it would help me.  Its technically called “Obstacle Avoidance Priority” and although it makes sense in hindsight at first glance I didn’t imagine that other AI NavMeshAgents would be considered “obstacles”.  In fact there is something else in the engine specifically called a NavMeshObstacle which I was just fiddling with yesterday.

Wednesday October 11

I haven’t done much in the last week but today I got some good info from this video which showed me how to make my game look better reasonably quickly.  I can see how this will help but at the same time I did some of the steps and my game didn’t instantly look better but I think with some tweaking it will.

Wednesday October 4

Just got back from Pennsylvania where I went to visit my sister, brother-in-law and niece and I made some progress while I was there specifically making the title screen level select much scroll much smoother.  I also re-did the making of video that I did a few weeks ago shortening it from 6 minutes to 2 minutes.

For my scorch game while I was in Pennsylvania I made it work with two players with shooting on different sides of one controller and balanced out the explosions.  Yesterday I made it keep track of scores for each player

Scorch with Scores
Scorch with Scores

Also I created a video about the simplest way to add a HUD and set the values from anywhere in your game:

And on top of all that I made my first full tutorial series in its entirety today!

http://johnmcgarey.com/2017/10/04/unity5-scorched-…tutorial-in-2-5d/

 

Monday Sep 25

Got a Level Select screen working that lets you clumsily scroll through the levels and select one.  it definitely works but the clumsy parts are the scrolling is abrupt and not smooth, the images in the rear are confusing, button presses get confused when you press too quickly, behind the scenes the image is not the same object as the scene number (they are aligned so it works atm but …) and the the whole look and feel of the screen is inconsistent.

I’m still proud that it works because now you can fire up the game, select a level, then go play that level and get a high score on that level.  Thats a complete one way game!

Level Select Screen
Level Select Screen

Sunday Sep 24

Worked on some side projects today mostly getting the Survival Shooter meta-tutorial done, but also figuring out how to launch projectiles and making a tutorial about that.

Also made some cool little glitches:

and

Saturday Sep 23

Got a pong game working.  Started today.  Finished today.

Friday Sep 22

Last night a friend (Gary) came over and spent some time with my game.  He said that I had made a lot of progress and I appreciated that he came by.  In order to show him the progress I had made I tagged some commits in my git repository and then went through them in stages and today I went back through the same commits in this video.

It shows ho I started this project on August 13 and the progress I made every week or two since then (and there has been a LOT).  Its pretty cool to see the contrast between the first few versions and the latest and it makes me proud of what I have done.  More details are in the ~6min video.
In addition today I got independent high score tables working for each level.  And I figured out a pretty good method for accessing non static singletons statically.

Thursday Sep 21

Fixed fonts and got bouncing off the walls working better

 

Monday Sep 18

Got the High Score system working pretty well yesterday!  I animated the score popup so it spins around gracefully and I also went through every level and changed all the prefabs to match my latest configurations so they all play about the same with the only difference being the landscapes of the levels themselves.  D’oh!  I just realized that I forgot to add power pellets … oh well thats probably a 10-15min total task.

 

Friday Sep 15

Added a title screen and got the HUD text looking way better and more consistent

And I figured out how to really use TextMesh Pro (at least for in game text meshes, using it like this for UI text meshes is still a bit of a puzzle)

Text Mesh Pro
Text Mesh Pro

Got the trick with using 3d in the UI mostly figured out

Wednesday Sep 13

Ive been thinking a lot about scoring but as a result didn’t make a ton of progress in the last few days … until today!

Got a score plugin working (so it tracks your high score persistently) and a score UI setup.  and fixed some problems and made graphical improvements (for example the warp tunnels are cool spirals now).

Added hula hoops to indicate lives, and made the game reset when all of your lives are used up.

Also I got Super Beldevere to shrink when he is losing his powers after he has eaten a power pellet (and added a grace period so you don’t get too caught off guard when he’s just barely done shrinking).

 

Friday Sep 8

Got scoring popups working.

Thursday Sep 7

Tons of progress today.  I added scoring, multipliers, Simple GUIs for both, got the basic mechanics of powering up with a power pellet and eating ghosts figured out, refined the ghostie radar, refined the wall bounciness (so its not *quite* so crazy launching the player – see video).  All that happened really in 3 hours in the evening after having thought about it all day (tbh I also binge watched Voltron and played Shantae on 3DS which made room for the creativity to blossom!).

 

Wednesday Sep 6

In the last few days I’ve made some nice progress.  Made an 8th and 9th level, balanced the gameplay, added zen mode (so it doesn’t start you over if you get hit), and I came up with ideas for how to best do scoring (which is the next thing I’m working on).

Today I got a ghostie radar working so they don’t blindside you when you’re flying around the level.

Tuesday August 29

Worked with vectors to get a cannon onto Beldevere’s head for the scorch game.  Made a really cool level 7 for Beldevere: Interstellar Hero

Also Added a tail (or hat or nose) and a tail attack to kill the ghosties and  a gravity collector.

 

Monday August 28

Autogeneration works although I had some quirky behavior for a while (see Popcorn Bricks).  I’m proud that I got a basic implementation of the launching of a physics projectile working from a primitive gun without any help from the first person shooter starter kit pro.  Probably going to use my PacMan game as a starting point for this one.

Sunday August 27

Began a Scorched Earth/Tanks style game.  Autogenerating a stack of bricks to play around in.

Saturday August 26

Quakecon was awesome.  The competition was intense.  Doom VFR blew my mind.

Friday August 25

Created several more levels of Beldevere.  Each level is more refined than the last so I will probably have to go back and refine / re create the first few levels.  Got AI working smoothly late last night.

Thursday August 24

Tentacles to see what PacMans Ghosts are targeting

Wednesday August 23

Today I cancelled the project I was calling Gauntlet.  I trashed the project files and data, but I did keep the prefabs and scripts.  Update: in the intervening week I have found it difficult to re-use those prefabs (dependency hell).  Lesson learned: theres probably a way to standardize this somewhat … OTOH some of those dependencies are due to the FPS Starter Kit Pro.

This includes some Building Geyser

Unity5 Quick Set Object Placer Grid Snap Tool

Unity5 Quick Set Object Placer Grid Snap Tool

Quick Set Object Placer in the Unity5 Asset Store

Have you ever noticed that Unity5 doesn’t have any snap to grid functionality?  Its conspicuously missing even though its in most other tools like this (Unreal, Blender, Maya, Etc.).  Never fear because Unity Technologies have provided a way to add substantial new capabilities to the editor through something called editor extensions.

Grid Snap Extensions in the Asset Store

There are a number of extensions in the asset store which allow you to snap your objects to a grid, but I have only tried this one called Quick Set Object Placer (free version) and it is actually awesome.  There is also an inexpensive paid version which I haven’t tried.  The following videos show you how to leverage it and help you get around some of its quirks.

Installation and Setup

It is really easy to use.

 

Advanced Usage and Prefabs

There is a quirk with using prefabs but it works really well if you just do this one extra step that I show you in the video.

 

Organization and Prefab Offsets Matter

In this video I talk about how to have it automatically organize your painted objects for you and also I talk about why offsets in your prefab can make a big difference (for better or worse).

An apparent problem (and a solution)

It seems to be snapping objects at the wrong place, and it seems to be incapable of putting them at the *right* place.  Primarily it ended up being a viewing window perspective/iso issue and when I fixed that the problem went away.

Asset Modernization Guide – Procedural Examples

Asset Guide – Procedural Examples

This is a simple guide to an asset in the Unity3D Asset Store called “Procedural Examples”.  It states that it requires Unity 3.5.6 or higher which was written about five years ago so this asset is old and has experienced substantial rot and when you import it it doesn’t run.  This guide will help you get it running in 2017.1 and help you experience most (if not all of what it has to offer).

https://www.assetstore.unity3d.com/en/?&_ga=2.258807946.1438654072.1502225756-817480689.1498423427#!/content/5141

Most of it actually works (after you do this one thing).

I wrestled with this asset for a few minutes and got nowhere so feeling dismayed I put it away and came back to it a few days later and when I looked at it with a fresh set of eyes and a new determination I decided to start removing things that didn’t work to see if any of it would work at all.

First I found several significant errors in the Lightning script so I tried to update them, but I didn’t get very far before I got discouraged and had to admit I don’t know enough about the old particle systems vs the new to be able to port this script.  At that point I gave up and just deleted that script and gave up on that particular example but if anyone knows an easy way to get it working again let me know.

Once I did that all of the rest of the examples worked quite well!

How to use the procedural examples

When you import the asset into a new project you get this: (note: ignore the Textures folder – I added that later).

Unity5 Procedural Examples Asset Folder
Unity5 Procedural Examples Asset Folder

In the top level directory is the set of examples and all of them except for Lightning bolt work just fine. Just double click on them and go for it.

Some really cool results and effects

Most of them are either self-explanatory or come with simple in-game instructions in the top right. My favorites are below (Extrusion was actually really cool)

Unity5 Procedural Examples Extrusion
Unity5 Procedural Examples Extrusion
Unity5 Procedural Examples Heightmap
Unity5 Procedural Examples Heightmap
Unity5 Procedural Examples Extrusion
Unity5 Procedural Examples Extrusion

Quality

There are still some bugs here for example in the extrusion example if you make the ‘time’ too long then that shape just disappears saying that the triangles are out of bounds.  As a result these aren’t going to be good platforms for production code but using their techniques and building upon them is certainly a workable implementation.

Conclusion about the Unity5 Procedural Examples

This is a good set of examples for how to manipulate meshes procedurally and I’m glad that its out there.  It could clearly use a refresh and one of the examples doesn’t work at all but otherwise its informative and pretty easy to get working and could be of value to a lot of us developers.  Thanks Unity Technologies!

 

Unity5 – Learn With Me

Simple Test Environment (aka STE)

Many of the tutorials or examples I make will refer to the STE (aka Simple Test Environment) which is a scene with which you can do a lot of different stuff and it only takes 5 minutes to setup.

Learn about Layers

Simple way to add ‘billboard’ text into your game

Simple way to make Billboard Text SPIN in your game

 

Leveraging the Kenny.nl packs in Unity3D

Leveraging the Kenny.nl packs in Unity3D

Kenny.nl

 

Importing a Kenny.nl pack

 

A quick way to build buildings

An even quicker way to build buildings

Oops!  Accidental Building Geysers

In the process of making procedural buildings I accidentally created this:

And this

And here is how I did it

Unity5 Implementations (aka How to do shit)

Unity5 Implementations (aka How to do shit)

In Unity5 there are often many different ways to accomplish your goals.  Additionally there are many different things you can do but it isn’t always obvious that they are possible or how to do them.  This page shows you implementations of things that can be done in Unity3D v5 which is why I subtitled this article: How to do shit.

Inversion Of Control

If you want to do Inversion of Control or Dependency Injection in Unity this is how

https://strangeioc.github.io/strangeioc/

and use UNIRx for less tightly coupled code

https://ornithoptergames.com/reactiverx-in-unity3d-part-1/

or

https://github.com/neuecc/UniRx/blob/master/README.md

How to make things move smoothly

I was looking into available “tweening systems” this evening and found more than I bargained for:

Tweening Systems:

  1. iTween is the most popular but everyone complains about it having garbage collection problems.
  2. DoTween and LeanTween are the runners up in the popularity contest but they don’t have any GC issues and are probably better choices overall
    1. DoTween is documented better and some say is laid out better and is perhaps a more “complete”package but it requires that you get comfortable with lambda expressions
    2. LeanTween has less documentation and examples but many people say it is straightforward, and incredibly fast
    3. They are both free and open source

Alternatives:

Theres this package called “Movement Over Time” which apparently does things different than a tweening system and is “more like a whole new way of thinking of and doing movement in your game” (from one of the reviews on the asset store).  the same reviewer also said “I am amazed by all the new things I can do in only a couple of lines of code in this framework that seemed impossible before.”

Then I learned about Animation Curves which are built in and can apparently be used in the context of lerping to make that process entirely easy:  transform.position = Vector3.Lerp(fromPosition, toPosition, animationCurve.Evaluate(t));

In the process I learned more about events and delegates which is really powerful shit

How to set pseudo breakpoints

Just put this in your code and the unity editor will pause when it is hit.

#if UNITY_EDITOR if( Application.isEditor ) UnityEditor.EditorApplication.isPaused = true; #endif

Audio

Some say not even to try to use Unity’s built-in audio system but to use Fabric instead: http://www.tazman-audio.co.uk/?page_id=73

It looks like you have to setup an account to download but otherwise it is free for Indie studios and has a licensing payment plan not-unlike Unity itself.

Trying things out quickly in the editor

Add a button or context menu tag to your code

https://docs.unity3d.com/ScriptReference/ContextMenu.html

    [ContextMenu ("Do Something")]
    void DoSomething ()
    {
        Debug.Log ("Perform operation");
    }

About automating Unity builds with Jenkins

How to make a map from an excel spreadsheet

http://saor-gaming.co.uk/tile-based-map-generation-sabrecsg/

How to make Editor Scripts

Heres an article about a number of things including Creating Editor Scripts.

http://saor-gaming.co.uk/tile-based-map-generation-sabrecsg/

 

Terrains

This shows how to draw a pattern and make a terrain out of it!

 

This shows how to make a terrain in Unity that resembles a part of the planet ear

Simplest setting of HUD text

Making the Graphics better in Unity (more like Unreal)

Making a High Score Screen

Making Warp Points

 

Simplest Texture application in Unity3D

 

Lists of other implementations

Here is a large list of GIFs of Unity tips and tricks

 

 

Unity3D Great Code Snippets

Unity3D Great Code Snippets

Why can’t you type these in for us?

I could totally type these in for you but I choose not to because I don’t want to and because there is inherent brain/learning value in typing them in yourself and I believe you will get more value out of this page if you type them yourself.  I type them in again every time I use them.  Start typing or find the answers somewhere else.

How to do something periodically

The easiest way to do this is with “InvokeRepeating”.  The second easiest way is with a coroutine.  But if you want to do it with code in the update method:

How to do things periodically
How to do things periodically

How to Drag an object with the mouse

How to Drag an Object with the Mouse
How to Drag an Object with the Mouse

How to quit your application

How to quit your application
How to quit your application

How to affect a bunch of GameObjects at once

How to delete a bunch of GameObjects at once
How to delete a bunch of GameObjects at once

How to do Collision Detection

How to do Collision Detection
How to do Collision Detection

How to add a menu item to Unity

How to Add a Menu Item in Unity
How to Add a Menu Item in Unity

Cycling through an array the easy way

This is how to set an object to a different texture every time you press the space bar.

Its elegant in its simplicity

Cycling through textures with mod
Cycling through textures with mod

 

Leveraging Unity FPS Starter Kit with Unity 2017

Leveraging Unity FPS Starter Kit Pro with Unity 2017

This is the starter kit I am speaking of here:

https://www.assetstore.unity3d.com/en/#!/content/59977

I downloaded the lite version the other day and spent some time tweaking it this morning and decided that it had enough features and quality to go ahead and pull the trigger on the Pro version (its only $10.00!?!)

Importing the assets

 

This video is a virtual unboxing of the FPS Starter Kit Pro.

I import the assets, fire up the demo game, and then modify some parameters to make it more playable so we can see what it has in store for us.

Fun Easter egg: near the end of this video my mouse disappears.  It wasn’t there when I was looking at the screen but the screen recorder superimposed it back in.  I was moving my mouse blindly trying to click on the exit button and without knowing where the mouse was I was able to hit the exit button twice!  #mousingpride

Documentation

Making a Few Improvements

How to exit the game

How to make enemy spawning more consistent

Adjusting Weapons (and other player settings)

Applying the FPS Starter Kit in an Original Scene

Reloading the current scene when you die

Explosions

Waves of Enemies

Finishing a Level and Switching to Level 2

Level Advancement From one level to the next

Get Pause Working

Timeshift (making the game run slower or faster)

Short Pause when Level Complete

Adding a text HUD (and fixing warnings in the bargain)

Fixing GUI to Fix Warnings

Fixing the Pause menu and Locking the Mouse Cursor

Making a Prefab from Player + GUI

Improving the looks of the Floor Texture using Normal Maps

Improving the looks of the Weapon using Normal Maps

Lighting was getting dark upon reload

Found out a Unity5 quirk:  that this darkness (double-baking) is somewhat expected when we auto-bake lighting (which is enabled by default) for every scene we create we need to do one of two things: change the lighting from automatically baked to manually baked and then every time you change the lighting go bake it manually.  Or live with it while we are editing. It apparently never follows a deployed build into the field so it won’t be a problem long term.

Making the Sun Rotate Around the Playfield

Updates:

Well I’ve been using Unity FPS Starter Kit Pro for many weeks now and it has proven to be pretty good.  Still there have been some annoyances and some of them are documented here along with other things I find as I use it.

Problem with Rockets

I have found an intermittent problem with launching rockets at your foes that is making me want to find a totally different solution (perhaps download another FPS kit or build my own rocket and/or AI implementation) since I really wanted to use rockets in my game.

ProblemWithFPSStarterKitPro125spdrockets
ProblemWithFPSStarterKitPro125spdrockets

As you can see in the above gif rockets sometimes just don’t hit the target when they clearly should.

Its not a collision bound problem.  Its worse as the speed of the rocket increases but it is somewhat of a problem at any speed.

Problems with enemy Rockets

  • The Enemy doesn’t aim their rockets.

They are just shot out straight from their launcher (or at the same angle every time) which means if the robot model is bigger than you then it will basically only hit you with good luck.   Sorry I can’t get a video of this problem at this time but just imagine  the gif video with that robot shooting rockets at you and they fly all around you but none of them hit your or explode anywhere near you.

  • The Enemy blows themselves up.

If they are walking towards you launching rockets but there is anything in between you and them they will just keep shooting and hitting the object until as they get close enough that they are inside the explosion radius at which point *boom*.   On a related note if there are two enemies spawning from the same location they will inevitably as they are both proceeding directly towards you, get in the line of fire of each others rockets and shoot each other down. I was actually play testing a level I made and found out that all of my 25 enemies had killed themselves or each other!?!  Solution: I modified the rocket’s ‘physical explosion’ code and made it specific to the robots (previously it was common for the robots and the player) and added a check for whether a robot (tag of “Enemy”) was the collider that was within the explosion sphere when it got called back for the collision.

Documentation

Its large and not that helpful.  My tutorials here are vastly more useful for anyone who wants to start using this asset.

Plus theres the fact that literally half the size of the entire asset pack is what amounts to a 10 page PDF (with about as many words).

 

Some of the things I did to get it working for me

Unity5 Git log of my FPS Starter Kit Pro Project
Unity5 Git log of my FPS Starter Kit Pro Project

Leveraging my BasicGameKitv2

 

Using git with Unity3D

How to use git with Unity3D

The official documentation is here but I can’t recommend that because I found this answer on StackExchange which very nicely sums up what to do, but I haven’t tried it yet because I got distracted by this cool site:

gitignore.io.

I was looking for a good .gitignore file for Unity3D projects and I found that a semi-official one is maintained here but I also noticed that there is a cool website that has .gitignores for tons of different types of things: https://www.gitignore.io/

for Unity its:

https://www.gitignore.io/api/unity

In 2017 I used exclusively the command line git client but recently I’ve been using Git Kraken as a client and it has been working for me very well.  I think the biggest advantage I can think of right now is having the tree of branches visible at all times.

Fork then do a Pull Request

Here are the best instructions for when you are working with someone else git repository:

https://gist.github.com/Chaser324/ce0505fbed06b947d962

Try it by pulling some cool scripts and projects from GitHub

  • https://github.com/MaYiLagann/EscapeBattle
    • This takes some finagling to get working

Unity3D Meta-Tutorial for Survival Shooter

Unity3D Meta-Tutorial for Survival Shooter

On the main page for this tutorial I learned that this tutorial was the end result of a public speech at a conference.  Every year there is a conference called ‘Unite’ where ‘Uni-tics’ (thats a portmanteau of unity and lunatics) (of which I am one)  get together to talk and learn about Unity3D and in 2014 this tutorial was one of the talks at that conference.  You can get the slides that they presented at the time from the main page (linked above) and here is a youtube playlist with all 10 of the videos.

Pro Tip: As you are watching the videos, if you want to watch them faster, youtube (desktop) lets you speed up the videos and since its so easy to pause them you can speed through most of the stuff, then pause and implement what they say to do, and then unpause and proceed with the rest of the tutorial.

Pro Tip 2: If you want to go really fast then turn on the closed captioning so you don’t even have to try to keep up with their high speed spoken words.

Further Resources:

If you get stuck along the way please contact me.  I would like to help.  If you want to dig into it on your own then consider looking at the following:

  1. the support forum thread for this tutorial
  2. the “upgrade guide” that is in the assets folder of the project created (once you’ve downloaded the project files) (its called “Tutorials-SurvivalShooter-Upgrade to 5.pdf” and you can’t see it from Unity so you”ll have to navigate to it through the file system)
  3. the comments on the youtube videos (I’ve discovered that these can be quite helpful sometimes!)

Also it’s worth noting that all of these videos have youtube live transcripts so you can read what they are saying (roughly) and click on a line to jump right to that spot in the video.  This lets you skip ahead or back up in the video easily.

What is this ‘Survival Shooter’ that this tutorial speaks of?

Sometimes a picture tells a thousand words.

Sometimes a moving picture beats a thousand pictures.

 

Survival Shooter
Survival Shooter

 

Environment Setup

Video Duration: 10m11s

This tutorial as a whole has a lot of spit and polish to it.  Its targeted at complete beginners and as such it starts off helping you get Unity3D setup the same way they have it so things are more likely to look and work the same.  A substantial caveat is that these videos were posted in October 2014 so I predict that there will be some level of tut-rot but never fear my dear reader because thats what this meta-tutorial is for!

Where is my project data

The tutorial videos gloss over this completely (wtf!?!) so I’ve made a simple video to show you how to do it.

The project data is downloadable from the link on the main page of the tutorial

Link to Project Data
Link to Project Data

Delete the Directional Light

In the Upgrade Guide it says that you need to delete the directional light from the Hierarchy pane.  That light comes as a default light in Unity 5 and didn’t in unity 4.6 and the lights that they have you import are perfectly suited to this game so the directional light just disturbs the lighting balance that they had developed.

Tip – Convert project panel to list view.

A good tip I just learned is that it is easy to convert the project panel to list view simply by dragging the slider down to 0.

Project Panel to List VIew
Project Panel to List View

Missing Folder

In the video and the narration they speak as if there is already a folder in assets called ‘scenes’.  Well in the project I downloaded there is certainly not a folder called scenes. The narration seems to imply that you shouldn’t put it in the assets folder directly but in a subfolder so make a scenes folder in assets if its not already there.

Background Music

I don’t know if the bgm is supposed to play when I hit ‘go’ but it didn’t until I checked ‘play on awake’ (which they talk about in the video).  I’m going to uncheck that now to match the settings in the video.

Directional Light

In the Upgrade Guide

Implementations learned in this section

  • Adding background music
  • Converting project panel to list view
  • Object Layers (just a touch)

Adding the Player Character

Video Duration: 35m51s

Adding an Animation Controller

Just prior to actually adding the Animator one of the speakers talks a bit about .fbx files and how the animations are stored within the model.  He also speaks of ‘retargeting’ a process in which you apply an existing animation to another skeletal model but in order to do this the model must have been through a process called ‘rigging’.  I don’t believe we will be doing that in this tutorial (since this player model is much simpler and rigged ‘generically’) but this is how many models are animated after they’ve been created and I’m glad he mentions it here.

He explains that the Animation Controller is a state machine that controls when each of the animations that already exist in the player model are going to be played back.

Once again the folder that they say is there is not so you will need to create a new ‘Animation’ folder in the project pane.

There is a Discrepancy in the settings

I just noticed something possibly slightly disturbing:

Different default settings
Different default settings

Both ‘Culling Mode’ and ‘Apply Root Motion’ are different!  Lets see if there is anything about this in the ‘upgrade’ document in the root folder of the project… Aha!  yes it does address ‘Apply Root Motion’ and states that it won’t matter.  For the purposes of this tutorial I am going to assume that they also believe the difference in culling mode won’t matter and I will proceed with the tutorial.

Adding Animation Parameters

The upgrade guide mentions that the parameters are no longer in the bottom left but in a tab in the top left.

At 9m53s he explains that a trigger is like a boolean but it resets itself back to false as soon as it has been consumed so it can be used to trigger things to happen once.

Important Note: For every transition in this tutorial you must uncheck ‘Has Exit Time’ (found that note in the upgrade guide AND in the youtube comments).

Physics Rigidbody

Setting drag and angular drag to infinity is an interesting approach that I haven’t seen before.  This means the player will stop instantly instead of floating along at all in the direction they were moving.

Implementations learned in this section

  • Adding an animation controller
  • Viewing built in animations in a model
  • Importing animations into the Animator
  • Finding animations within an FBX file in the project pane
  • Adding animation parameters
  • Transitioning between Animation states
  • Adding a rigid body for physics

Coding the Player Character

(same video ~19m10s)

This section speaks about some new things:

  • FloorMasks LayerMasks and RayLengths
  • FixedUpdate vs Normal Update
  • Normalized Movement
  • Time.DeltaTime
  • Raycasting

This seems to be an advanced and mature way of controlling the character and I am probably going to use this in other games.

Wow! By the time this video is done movement works and its pretty darned cool seeing the player character bumble and jump and twist like that!

Implementations learned in this section

  • A great way to control a player based on raw inputs
  • Normalized movement
  • Rotation based on the ray cast between the player and the mouse

Camera Setup

Video Duration: 9m15s

Topics and Implementations touched upon in this section

  • Orthographic Cameras
  • Camera following the player
  • Smoothing (so the camera movement isn’t quite so abrupt)
  • Vector3.Lerp to help with smoothing
  • Time.deltaTime to make your game frame rate independent

The Scripts/Camera folder doesn’t exist so you’ll need to create it.

Note: You must set ‘clear flags’ while you are here to ‘solid color’ (see the upgrade guide for a bit more info)

Time.deltaTime to me doesn’t makes sense (it obviously works I just don’t know what it really means).  I’m going to look it up with CMD or CTRL + ‘ … ok I learned that it is the time since the last frame (context sensitive to Update or FixedUpdate) so this would be some number of … microseconds (I presume)? Ok this screenshot from the documentation helps a bit:

Unity3D Time.deltaTime Documentation
Unity3D Time.deltaTime Documentation

Adding the First Enemy

Video Duration: 23m46s

Findings

I found the difference between a normal collider and a trigger collider interesting in that the trigger collider doesn’t take place in any physics interactions.  Instead a function is called behind the scenes whenever it collides with the player.

Navigation

The Nav Mesh Agent section made me wonder what would happen if I didn’t change any of those values … I might try that later (after this all works).

The layout of these navigation panes both  looks slightly different from the video.

Note: The Upgrade guide says that you must set Step Height to 0.34 and Manual Voxel size to 0.25.  There is no width inaccuracy anymore.

I am going to remember that anytime you change the position of static objects in your scene you will have to re-bake the navmesh for things to work properly.  That seems like something that could easily ‘bite’ you in the future.

Problem: Not being followed

In the video the bunny is following the player but mine is just ‘walking’ in place.  Lets see if I did everything … ah there is an error in the code!  Actually as I look deeper it wasn’t an error in the code per se.  The code was looking for a game object with a tag of ‘player’, so I had to tag the player with that tag.

Unity3D Tag the player
Unity3D Tag the player

I went back to video 2 and confirmed that they DO tell you to tag your player with the player tag.  Mine wasn’t tagged so it was somehow my mistake.  I either missed doing it or I did it while I was in play mode (which cancels out everything you did when you exit play mode).  Done. Fixed. Moving On.

Topics and Implementations addressed in this section

  • Importing rigged and animated enemy characters
  • Particle systems
  • Shootable layers
  • Physics Colliders
  • Trigger Colliders
  • Nav Mesh Agent
  • Navigation Baking
  • Animation Controller for enemies
  • Enemy following player

Health UI

Video Duration: 14m07s

UI is large

They talk about how large the UI is in relation to the game units (one pixel per game unit) but they assure us that is not an issue.

 

Topics and Implementations addressed in this section

  • Rect Transforms
  • UI Pivots
  • UI Anchors
  • UI Canvases
  • UI Canvas Groups
  • UI Images
  • Making a health slider
  • Removing the button from a slider
  • How to cover your entire canvas with a UI element

Player Health

Video Duration: 17m10s

Some Health code that needs Tweaking

I wired up a way to cause myself to take damage (just so I could test it out) and I noticed that even after I was dead I was taking damage and making “ow!” sounds.  I checked to see if I was dead before taking damage and that fixed it.

Problem – Slider is not working

I went back and looked closely at what I had done compared to the slider in video 5 and found the problem.

The problem was that the Min Value was set to the same value as Max Value.  As soon as I changed Min Value to 0 it all worked!

Topics and Implementations addressed in this section

  • Script Interactivity (from one script to another)
  • Player Health Management
  • Player taking damage from beasties
  • Lerp-ing from one color to another over time
  • Collision Spheres (OnTriggerEnter)
  • Affecting a GUI slider with real game data

Harming Enemies

Video Duration: 41:03

Wow.  This is the longest video so far by far.  Its an important topic but having never watched it (as of the time of the writing of this sentence) I wonder what kinds of things are we going to be doing that would take 40 minutes!?!  I guess we are about to find out!

Ok the first 10 minutes is a walkthrough of code they have already written for you which will give health to the enemy (aka the ZomBunny) but I found it interesting that when you view the animations for the Zombunny you find that it just calls a public function called “StartSinking” whether it is there or not.

Then they spend way too long explaining block comments which is a pretty standard programming thing.  I realize that not everyone will know what they are and that some people will benefit from them, but they have assumed a certain level of experience thus far and could have stuck with that IMHO.

Major Discrepancy: Line renderer

Well when it comes to changing the ‘parameters’ of the line renderer … well … there ARE no ‘parameters’!?!  So I’ll try to figure out what to do instead.  ok I’m back and I’m still not sure what to do so here’s what I did:  I made Width = 0.5 and dragged that little red dot on the graph down to 0.1.  When I tested the work we did in this section that looked just fine, but there might be a more ‘authentic’ way to do it (so to speak).

Unity5 line renderer problem - no parameters anymore
Unity5 line renderer problem – no parameters anymore

After this they walkthrough a script for 15minutes then they test the game.  A few things I noticed: My gunshot sound is quite a bit lower pitched than theirs.  Also my player shoots much slower than theirs.  The gun sound doesn’t matter, but the player shot speed does; I fixed that by going to Player->Player and changing time between shots from .15 to .12 (its a very sensitive value).

P.S. The error at the bottom of the screen about a navmesh is deliberate (they mention that in the video but I wanted to give you a heads-up!)

Overall this was a pretty easy section without too many problems.

Scoring Points

https://www.youtube.com/watch?v=SOmBhbVz5yQ

In this section they are making a score UI and setting it with values when you destroy the enemy.  It talked about static classes and class data and when that will be useful in this section.  I encountered no problems during this section and I think it was well done.

Implementations:

  • Use of Static Variables

More Enemies

This one starts out with a puzzle: The prefab they are suggesting that we use isn’t there!?!

Prefabs aren't in the folder
Prefabs aren’t in the folder

At around 1:00 in the video is suggesting for us to use the Zombear from the prefabs folder but in my prefabs folder its not there!?!  Well that is true and this is a legitimate small error in the tutorial but I found it somewhere else: in _CompletedGame/Prefabs its in there.

Similarly the “Character” they refer to are not in the “Characters” folder but instead in the “Models/Characters” folder.

At about 9:00 in it shows you how to spawn new enemies and I feel like this is a particularly elegant solution in a number of ways.  It lets you have multiple spawn points, invokes a function regularly (I honestly didn’t know about that trick), and stops trying when player health is zero.  It also is modular so you can drag more than one copy of this script onto your enemy manager to spawn different enemies.

At the end of the video I encountered a problem because one of my enemies was moving around but the other two weren’t.  hmm …I’m going to try not spawning enemies but simply placing one in the game world and see what happens.  Ok I solved it by removing the “enemy Health” and “Enemy Movement” scripts and re attaching the components from our scripts folders.  For some reason that worked.  I suspect it was using slightly different (and broken) scripts from the _CompletedGame/Scripts folder.  Sure enough they are different in one fundamental way: they use a different namespace.  For that reason you will need to copy over the Enemy Attack script as well.  If you want to go all the way you will need to also add the death sound to the enemy health script.  When you do the settings will be different:

Hellephant Settings
Hellephant Settings
Zombear Settings
Zombear Settings

Yeah replacing all of those scripts seemed to do the trick.  and the game actually works really well now and is pretty fun!

The Game is Pretty Fun Now
The Game is Pretty Fun Now

 

Game Over

This is a really cool section.  In this section we are going to make a cool screen that overlays the game showing when the game is over but more importantly I think they show us how to animate any property of anything in the game!

The process to create a new animation has changed: In the video they refer to something called “Add Curve” now its called “Create”:

Create an Animation
Create an Animation

After that they show you how to set all of the values which is straightforward, then they drag a script onto your HUD Canvas, however the script they show in the video has one important thing that the script included in the assets folder does not: a restart timer to reload the level after a certain amount of time has passed.

If you want to add the restart time then this code should do the trick:

restart Level Code
restart Level Code

(note lines 4 and 26 in my code which are significantly different than the video)

I tried running my game without that restart timer code though and everything worked just fine!  The game even restarted after a second or two!  That must be an artifact of how they designed some of the other components of the game but boy it works great!

Implementations:

  • Animation of any public property of anything in the game
  • Doing something after a certain time has elapsed
  • Triggering an animation to begin

 

Final Words

This was an incredible tutorial.  You end up with a fun game and with understanding almost everything that they did to make it.  I’m really impressed with the quality but I still saw quite a bit of tutorial rot so I’m glad that I struggled through and documented what I found here for you.   Hopefully it was of benefit to you and I hope you learned a ton from the tutorial and got less frustrated thanks to my meta-tutorial.  Best wishes and let me know if you have any questions or comments!