THE OFFICIALEST BLAGGERS GUIDE TO MAKING A SURVIVAL HORROR GAME

In which you’ll drag until you drop!

[For Ashton]

We’re using Unity 3D to create our first person survival horror masterpiece! This will be superb. So, first things first, let’s go and download the free version of Unity (we’re blaggers, we ain’t paying for anything): http://unity3d.com/unity/download/

Now that’s done and you’ve opened Unity up, you’re probably feeling a little overwhelmed by all the gadgets and gizmos in the interface. Fear not – it’s all quite simple!

Unity GUI

Referring to the image above, you’ll notice that the top left image is labelled the “Scene” while the bottom left image is the “Game”.

We’ll be playing around in the Scene – putting all of our assets in there. The Game window merely shows what you’ll see upon playing the game; the player camera essentially.

Helpful hint: Think of a Scene as a level

To the right we have 3 columns. From left to right we have: a list of the things in our scene, the assets (script, objects) that we have available to use, and lastly is the Inspector in which we can fiddle with individual assets to how we want them.

Looking around the scene

Before we get started on making the game, we need to make sure we’re comfortable with looking around our scene, as this can be a pain in the ass if you aren’t familiar. So, clicking on something in your scene, the camera for instance, will select it and bring it up in our Inspector.

Holding down the LMB (left mouse button) within the scene allows us to select multiple things within a scene, much like selecting units in our favourite strategy games.

By pressing and holding down the RMB (right mouse button) we can look around the scene from a single point. The mousewheel can be used to zoom in and out. You can also zoom by pressing Alt and the RMB and then moving your mouse accordingly.

Alt and LMB achieves the looking around function once again, however, if you select an object you can use it to rotate around it while maintaining it centre screen. Try pressing the RMB and using the WASD keys to move around your scene too. It’s best to use all of these different methods rather than attempting to stick to one – it can be a pain to get the right angle but with some practice you’ll get it eventually.

Moving around in first person

Before we can start doing anything, we need to make sure we have all of the assets we need – because we’re blaggers and can’t code or make our own things! Go to “File” then “New Project”. You’ll see a little window come up asking you where you want to save the file. Sort that out if need be and then focus your attention on the list of packages below.

For our masterpiece we’re going to need to tick the box for “Character Controller”, “Scripts” and “Terrain Assets”. Once you’ve ticked those, press “Create” and you should see them foldered up in your middle column if everything has gone smoothly.

The first thing we want working is the player movement. For that, we’ll need a terrain to walk on. So from the toolbar at the top, click on “Terrain” and then select “Create Terrain”.

Simple.

Now, if you have a default “Main Camera” in the scene, click on it either in the Scene viewer or in the furthest left column and delete it.

Once that is done, head into the “Character Controller” folder in the middle column by clicking on the little arrow next to it. You should see two options come up underneath – “3rd Person Controller” and “1st Person Controller”. We want the latter – “1st Person Controller” – so simply drag it over to the Scene viewer and you should find you have a little mate.

It’s likely your character won’t be in the place you want him. To sort his round ass out, go into the Inspector with the First Person Controller selected in your scene, then find “Position” and change the X and Z variables to 10, while you change the Y to 1 so that he sits on top of your terrain. With that done, head back over to your Scene viewer and press F while in it to zoom to the location of your character.

Helpful hint: Use the movement arrows on the character to more effectively move them around in the Scene viewer. Look at the picture below to see what button needs to be pressed to ensure the arrows are available on your character (should be default anyway).

Asset Manipluation Buttons

Hopefully he is sat on the terrain and if you go to the top centre of Unity (just above “Hierarchy”) you should see a play button. Hitting that means you’ll be playing the game and you can walk about and jump. You can also fall off the edge of the terrain, which sucks. Just press the Pause button at the top to come out of it again.

To the top right of the Game viewer you can press “Maximize on Play” to play your game in the full Unity window rather than that pathetically small one. I prefer it at least.

You may want to adjust how fast the mouselook is, field of view and other such nonsense that comes with making an FPS these days. Where did the days go when using a keyboard to look around was fine? Oh wait, it wasn’t fine – it was shite. Well anyway, if you click on the arrow next to “First Person Controller” in the left column and then click on “Main Camera” you’ll be able to adjust these kinds of things in the Inspector, as you can see below.

Mouselook

Getting the right atmosphere

• So do you know what we’re going to do now? Add a really dark fog, that’s what! To do that we need to click on “Edit” in the toolbar, go down to “Render Settings” and click. This should bring up the Render Settings in the Inspector.

Over in the Inspector, make sure the box for Fog is ticked. Then go down to “Skybox Material” and double click on the little circle. You’ll have a separate window come up with some random textures. We don’t really care which one it is because our fog will mean the player won’t be able to see it anyway. I went for “palmbark”, so just do that if when in doubt.

Now, further up the list you should see “Fog Color”, double click on the color bar and choose black (or whatever you want I guess). Now we have to add the “Fog Density”. This can be done by typing the number in, I recommend something between 0.09 and 0.20. Check it out by playing the game and you’ll notice we’ve made some good progress already. Oh, what good blaggers we are!

• Next let’s add some chilling music. Google free music or something similar, find a file you like and one that will loop well – Unity accepts most files. Once you’ve got your file ready, go to “Assets” in the toolbar then click on “Import New Asset”. Find your music file and then import it into Unity. It should now appear in your middle column.

Drag the music file from the middle column over to the left column and drop it on the “First Person Controller”. Then click on it to bring up the First Person Controller in the Inspector. Scroll to the bottom of the Inspector (right column) and you’ll see an “Audio Source”. This is your music file. Check the boxes for “Play on Awake” and “Loop” and then play your game to hear your new scary background music. You can fiddle with the “Volume” and “Pitch” however you want too.

• Now things are starting to make you tremble! We better get you a flashlight and fast! In the left column you’ll notice a “Create” button at the top. Click on it and then select ” Spotight” from the dropdown menu. This will make it appear in the column and the first thing you want to do is to make it a ‘Child’ of the “Main Camera”. You’ll find the Main Camera by clicking on the arrow next to “First Person Controller”. Drag the Directional Light into the Main Camera and it will become a child. This means that its movement and everything else is dictated by the Main Camera.

You’ll probably have to adjust the Spotlight to how you want it. Use the movement handles in the Scene viewer to put it in your character (as good as holding it) and then click the Rotation button in the top left of the viewer, the one just to the right of the Movement button, and use those handles to get the light facing forward how you want it.

As you have the Directional Light in the right place, go to the Inspector (with the Light selected) and fiddle with the “Range”, “Spot Angle”, “Color” and “Intensity” to set it up as you want it. You may want to come and change this later when we’ve added objects to shine it on.

Flashlight

We’re not done with this flashlight yet! We want to be able to turn it on and off, but for that we need coding and that’s something we cannot do! The only solution for us blaggers is to steal the code from someone who knows what they’re doing. After a quick Google Search we find the following script: http://forum.unity3d.com/threads/31926-Flashlight?p=207876&viewfull=1#post207876

function Update() {

if (Input.GetKeyDown("f")) {

if (light.enabled == true)

light.enabled = false;

else

light.enabled = true;

}

}

That’s the one we need! Copy that code and then head back to your Unity project. Now you can click “Create” just above the second column or click on “Assets” in the toolbar and then “Create” – either way we need to create a “JavaScript”. This will bring a “NewBehaviorScript” into the middle column, which I’m going to rename “Flashlight”, but it’s up to you.

With this selected, either double click on it or press “Open” in the right column. This will cause the “Assembly UnityScript” to open up. Delete the code that’s there and then Paste our copied code as a replacement. Save it and exit.

Back in our Unity project, we now have a “Flashlight” Script asset we can use. Just drag this over to the “Spotlight”. When you play your game again, you’ll now be able to press ‘F’ to turn your flashlight on and off. Yay!

Helpful Hint: Upon opening the “Assembly UnityScript” always make sure you are editing the right Script. You can switch between them all in the top left box and double clicking on the one you want. I say this because it often opens up the last one you edited rather than the one you opened. It’s weird.

Now you’ve put your first script in, try doing another one by just following the simple steps we went through. To make the act of walking have a bit more swag, let’s add a Headbobber.

You’ll find the script you need right here: http://wiki.unity3d.com/index.php?title=Headbobber

private var timer = 0.0;
var bobbingSpeed = 0.18;
var bobbingAmount = 0.2;
var midpoint = 2.0;

function Update () {
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
}

Just make sure to name it so you can find it, and drag it over to your “Main Camera” when you’re done.

You’re probably fed up of that bloody mouse cursor as well. Same thing as before – here’s the very simple script you’ll need to lock it to the screen (press Esc in-game to exit):

Screen.lockCursor = true;

Helpful Hint: You probably don’t want players to see the Capsule Graphic when looking down either. You can click on the arrow next to “First Person Collider” in the left column, select “Graphic” and then press delete to get rid of it. You don’t need it and players won’t see a little capsule bobbing around anymore.

Building a scene

We’re really getting somewhere now! But there’s still a lot missing. Let’s make a forest! Click on “Terrain” in the left column and then head over to the Inspector. Here you’ll see a header saying “Terrain (Script)” with a bunch of buttons in a row underneath. First off, find the one that allows us to paint the terrain texture (hover your mouse over the buttons). Click on it and then find a brush you like – the default one is fine.

Helpful Hint: There’s a free Unity Package with plenty more Terrain Assets available to download from here: http://code.google.com/p/vga-unity/downloads/detail?name=Terrain%20Assets.unitypackage Just click on “Assets” in the toolbar, then “Import Package” and then “Custom Package”. Find the “Terrain Assets” package and Import it all into your project.

Next go down a little further and click on “Edit Textures…” and then “Add Texure” from the dropdown menu. This will bring up a little window, in which, it will say “Splat” at the top and to the right of it another of those little circles. Click on the circle and find the texture you want for you forest floor. Double click on it, then press Add in the bottom right of that little window.

Back at the project, we can now paint that texture over our Terrain, so do that. If you want you can try raising and lowering your Terrain with the buttons on the left of that row, but it’s not necessary. We’re more interested in getting some Trees involved!

Trees aren’t quite as simple as ideally we don’t want players to walk straight through them. So, what we need to do is find the Tree we want in the middle column by clicking through “Standard Assets”, or, if you made the download suggested above, “Terrain Assets” and then clicking through to “Trees Ambient Occlusion”.

Find the tree you want and then drag it somewhere into your Scene. With it selected, click on “Component” in the toolbar, then “Physics” and then select “Capsule Collider”. This will be added to the Tree and can be fiddled with in the Inspector now. So go over to the Inspector and find the header “Capsule Collider”. All you need to do is make sure the “Radius” of the Capsule is the same as the Tree trunk, and that it is also in the centre of your Tree trunk. When you think you’ve managed to get the Capsule Collider to the same placement and Radius as your Tree, play the game and you shouldn’t be able to go through it anymore. Leave the Tree in the Scene for now.

If we want to save ourselves a job (we’re blaggers after all) then we’ll need to turn this tree into what is known as a Prefab. This is very easy to do. Simply click the “Create” button in the middle column and select Prefab. Name it something that you’ll recognise as your tree (for your same-tree forest). Done that? Great. Now all you have to do is grab the tree that you created a second ago and drop it into this Prefab.

Now that’s that sorted, we need to go back on to “Terrain” in the left column and click on the Tree button that comes up in the Inspector. Then, click on “Edit Trees” and then “Add Tree”. Click the little circle in the window that pops up. Find the Tree you just created, double click on it and then “Add”. Now you can paint the Trees on the Terrain as you did with the Texture. Make your forest however you want – the Density and Brush type can be changed to your liking.

Forest

Helpful Hint: It’s probably a good idea to grab the “First Person Controller” and move it somewhere near the middle of your forest now, so that the player starts within it.

Last visible thing for our scene is some Grass or Flowers if you’re feeling pretty – just something cover up that ugly floor texture. Same drill as before; select the button on the Terrain Inspector that has some flowers as an icon. Click on “Edit Details” and then “Add Grass Texture” from the dropdown menu. Click on the little circle and find some grass that you like, double click on it, find a colour for it that you like and then “Add”. Get painting!

Of course, we really don’t want our players running off the edge of the Terrain, so what we need is some invisible walls! Go to “GameObject” in the toolbar, select “Create Other” and then “Cube”. The Cube will be really small to start off so select the button on the top left of the Scene viewer to make it bigger. Make it thin and wide so it really is a wall and not a curve. Put this along one side of wherever your want the boundaries to your level to be and then go back to the Inspector and at the bottom you’ll see a header called “Mesh Renderer”. Simply uncheck the box and your Cube, or wall, will now be invisible.

To create more boundaries just right click on the Cube in the left column and Duplicate and drag them into place. Sorted.

The deathbringer

You can’t have a survival horror without an enemy! This is probably the best place to make your own mark on the game, so try to find ways of making your enemy unique. I went for the pursuing black smoke monster…thing. It’s a simple particle system with a Sphere Collider attached so that when it hits the player they instantly die. Or will do, I haven’t got quite that far yet.

To make it pursue my player, I stole a bit of coding that I found, this one: http://answers.unity3d.com/questions/274809/how-to-make-enemy-chase-player-basic-ai.html

var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;

function Start ()
{

}

function Update ()
{
transform.LookAt(Player);

if(Vector3.Distance(transform.position,Player.position) >= MinDist){

transform.position += transform.forward*MoveSpeed*Time.deltaTime;

if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
{
//Here Call any function U want Like Shoot at here or something
}

}
}

You know the raw basics of Unity now, and using our blagging ways, you should be able to find a few things scattered around the internet to help you patch together something that resembles a game. As soon as I feel confident enough with providing a guide on making various types of enemies, I’ll update this post.

In the meantime, add some extra assets, create paths – go mental if you have the confidence!

Showing off

At any point during the development of you survival horror masterpiece you can create a build and share it with your friends. It’s very simple. First off, I would go and grab Dropbox if you haven’t already: https://www.dropbox.com/

So, while in your Unity project, go to File in the toolbar and “Save Scene” – just to make sure. Now, still in File, go down to “Build Settings…” and click. You’ll now have a separate window that giving you a few different options as to how you want your build to work. You can make a Standalone for Windows of Mac if you want. Just select what you want and press “Build” (“Build and Run” if you want to play it yourself straight away). Then your Standalone build will appear as a folder somewhere – you can put that in a zip if you wish and send it to people.

I prefer creating a Webplayer though, which is why you’ve downloaded Dropbox. Select Webplayer and one of the options – “Development Build” is probably best for now. You’ll then get a “Webplayer” folder with two files inside it. Take this folder with both of these files over to your Dropbox folder. In there, drag the Webplayer folder into your “Public” folder. Enter the Public folder and then the Webplayer folder too. Right click on the HTML file of your game, it should just be called “Webplayer”. On the dropdown menu that comes up, go down to “Dropbox” and then click on “Copy Public Link”. Go into your internet browser and paste the link you just copied into the address bar. You should be able to play the build of your game there and you can share that link with anyone you like and get them to play it too!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s