Getting Into Unity

3D and Game Enignes are my favourite areas of IxD. I already have some prior knowledge of Unity and C# from last year for my design domain project. I’m wanting to do a good job of this project as it’d be handy to have in my portfolio. Luckily, I’ve managed to get my hands on PluralSight so I’m going to try and complete some courses on it during this project.

PluralSight

Unity Fundamentals

Learn to create folders, import asset packages and placeholder objects.

When exporting 3D objects for Unity, it’s important to reset the transformations and make sure the pivot point is centred and facing the correct direction. Export object as .fbx. Export smoothing groups and Tangents and Binormals. Check the animation button if exporting an animation. Embed media will export the textures. Export units as metres. .FBX file can be loaded directly into Unity. Name materials in Maya/Max to avoid confusion.

Select mesh and rig- reset transform data etc. Use game exporter in Maya. Include skinning and blendshapes. Export as single file- up axis Y- embed media. In unity uncheck ‘import visibility’, ‘import cameras’ and ‘import lights’. Humanoid Rig animation type for humans or generic to keep settings. From Maya export animation also as an fbx.

Toolbar contains transformation tools (move, rotate, scale). Transform gizmos (centre or pivot) Local or global position. Play button, will run game. Pause, helpful for debugging. Step forward button to move frame by frame. Collab, load from cloud and account settings. Layers are helpful for organisation. And the layout tab.

Toolbar

Hierarchy allows for object creation, object selection, search for objects, see parents, children and groups.

hierarchy

The scene view allows for manipulation of objects. Game view will show how the game will appear when its being played. Asset store- download assets.

SceneView

Inspector displays objects properties and components (transform, scripts, etc.).

Inspector

The project window displays assets. Search and filters are available. Search by label. The console will show warning and errors when running game.

project

Customising Interface

Select and drag tabs. Areas on interface can be resized. Icons can be scaled. Add a window by going into window tab. Close tabs by clicking on fly-out then ‘close tab’. Maximise a tab.

UnityInterface.JPG

Navigation

Alt+ LMB will orbit. Alt + MMB will Pan. Alt+ RMB will zoom. Scroll also zooms. Fly-through- hold RMB to rotate your view ‘wasd’ to move around. If you are lost in the viewport. Select an object in hierarchy then press ‘f’ to snap to it. Perspective or Isometric view by clicking on cube in centre of navigation gizmo. 2D button will lock camera to 2d view.

Asset Creation

Use Inspector to change transform values. Hold ctrl to move objects in a snapping distance. Set snap settings in edit> snap settings. Hold ‘v’ to snap to vertices. Change objects’ names in inspector or delayed double click. In the hierarchy, drag and drop an object onto another to make it a child of that object.

Painting Terrains

Create>3D>Terrain. Enter terrain settings to change size and resolution. Use terrain up  to paint height onto the terrain. Flatten will set terrain to a height. Hold shift when raising terrain to lower the terrain. Smooth tool will average out heights. Paint textures and trees. Import raw files as height map.

Terrain

Texturing Terrains

Go into terrarin component > paint texture > edit textures… Select Albedo texture than normal if it applies. Will automatically apply the texture to the entire object. Add another texture, select it then you are able to paint with it.

TerrainTex

Materials

Apply metallic map- black areas have no metallic and white have full metallic. Normal map will make it appear as though the material had depth.

Texture

Colliders

Colliders prevent objects from passing through one another. Inspector>Add Component> … collider. Avoid using mesh collider as it will duplicate the object and will make the program run slower. On the collider click “Edit Collider” to interactively edit the collider. Or type in values for the collider size. You can add several colliders to an object. “IS TRIGGER” will allow objects to enter the collider.

Collider

Rigid Body

Add Component> Rigid Body. Unity will save processing power by putting the physics into sleep mode for a static object. Mass will increase an objects potential for force. Drag will simulate air/ fluid resistance. Angular drag will affect the air resistance for rotation. Use gravity value is determined by the preferences. Is Kinematic will turn rigidbody parameters on and off- this allows for scripting to allow it to be enabled or disabled. Interpolate checks previous frame and smooths out movement. Extropolate checks next frame. Collision detection is useful for fast objects. Physics frames play at a different rate to the game so sometimes objects can go through other objects. Using Continuous collision detection will prevent this. Or collision dynamic if this still doesn’t work. This requires more CPU power however. Constrains allow for scripting physics simulations.

RigidBodyy

Prefabs

Allows for instances of a premade object to be added multiple times to a scene. To create a prefab, drag an object from the heirarchy into the project window. Prefabs will keep all components. Change a component in one prefab, click apply, then it will change for all of the prefabs.

Set Dressing

Using the same props to create a scene.

SetDressing

Lighting

Rotating a directional light will change colour and intensity. Point light emits light in all directions- intensity decreases with distance. Spot light has a range and a narrow angle and specific direction. Area lights are rectangular and they have direction and is baked only. This means the light only works after the light is baked.

Placing and Manipulating Lights

Window> Renderer> Light Settings> scene. Set directional light as sun source then disable it to get a night skybox without any light. Scene lighting looks better than I remember. Lighting appears in patches on certain objects.

LightingCool

Optimising Lighting

Reduce range and increase intensity. When light ranges overlap they create this patchy lighting. This is due to per pixel lighting (shades an object at every pixel) vertex lighting (light assigns itself to vertex of an object then a different colour value to a different vertex of an oobject). Pixel lights are important (prioritised, higher res). Vertex lights are low res but dob’t require too much processing power. This can be chosen on the render mode of the light in the inspector. Edit>project settings> quality

Light Baking Techniques

Dynamic lights constantly emit light onto the scene. Light baking ‘bakes’ the lighting information into a whole ligh map that is applied to the environment as a whole. This allows for the scene to be optimised. Set mode in inspector to Baked. Realitme is most expensive. Baked light only casts on static objects. Indirect multplier sets the number of times light will bounce. Mixed lights are baked but you can only change intensity and colour.

BakedLighting

Creating Particle Systems

Create-> effects-> particle system. Emission allows for changes to the rate and number of particles emitted. Shape change

Editing Particle System Properties

Prewarm will make sure particle system is already running when the game starts. Size frequency  etc.

particleEffect01

Creating Materials for Particle Systems

Enable texture sheet animation in particle system. When creating texture for particle system, set the shader to particles> additive. In particle system properties, go into the render tab and change material.

Fire.gif

Baking Navmeshes

Pathfinding solution for AI and characters. Click to move system. Navmesh agent will work out a path to the location that is clicked. Window-> navigation -> Bake. Set the maximum slope character can climb, and max step height character can climb. Drop Height and Jump distances.

Navigation

Refining the NavMesh

Allow player to walk through small obstacles (foliage). Set navigation static off to include them in baked navMesh. NavAreas- walkable, not walkable and jump. If you need to create a “not walkable” area around a dynamic object, then you should use a nav mesh obstacle component. Set shape and size. Set carve. If object is destroyed, navMesh will re-bake itself during runtime.

Using NavMesh Agents

Add a “Nav Mesh Agent” component to the character. Set as humanoid and modify height and radius. Make sure character is on navmesh. In order to make the character move along nav Mesh you will need scripts.

Creating Scripts

Unity allows scripts in C# and Javascript. Most users tend to use C#. Double clicking on script now automatically open visual studio instead of monoDevelop.

libraries

The first lines of code when you open a script tell unity what libraries/ assemblies to use. These are called namespaces. Public/ private. :monoBehaviour allows for script to be used as a component. void Start() & void Update(). 

Understanding Code Flow

Namespaces give access to prebuilt classes. The class has to match the name of the script. Public is an access modifier- any class can access it. Class should be thought of as a container. Object oriented programming- create many scripts and be as decoupled as possible. Instead of filling one class with methods, each method should be its own class.

Understanding Variables

Variables should be defined as private within a class. access modifier datatype variable name. Changing an access modifier from private to public is known as exposing a variable. Exposing a variable will make it visible in the inspector.

Understanding Methods

keyword void is used for a method that isn’t going to return anything. After void  give the method a name and then (){code}. For code to run, the method must be called

Creating Animations

Create> Animation Open animation window. Add an Animation component to an object that select the animation. Change animation to a legacy animation clip by going on the animation inspector, click the arrow/3 bars to open debug inspector, then check ‘Legacy’.

In animation window, ‘add property’ will add a property to the timeline that you can animate. To change keyframe, you need to press the record button.

flicker.gif

Animator Controller

create > Animator Controller. Apply animator controller to animator components. Open animator window. Drag and drop animations into window. Arrows between them signal transitions. Adding a premade animation to a premade object.

Idle.gif

Transition Parameters

Right click on one animation > make transition> draw path to next animation. With default settings, the first animation will run until completion before it transitions to the next animation. In animator, choose layer, go to parameters, then choose data type. Then within the animation, this data type can be chosen to create a condition for the animation to play.

Transition.gif

Scripting Animations

Load in UnityEngine.AI library. Variable data types such as Animator, NavMeshAgent. To get a components properties, use variable = GetComponent<component name>(); .

transCode.JPG

Blend Trees

In animator> right click> new blend tree> double click> add motion field in inspector.

Blend field will create transitions for several animations.

Listeners Sources

Audio listener automatically assigned to camera. Audio source is a component- add audioclip to audioclip variable. Play on awake, loop.

Audio Mixers

Game object mixes all the audio sources. Apply effects.

Audio Effects

Press add at bottom of sound group> add reverb. Solo a sound group.

UI 2D Assets

2d assets can be used as textures, or UI. Texture type> normal map, editor GUI, sprite. Set max size of sprite.2DAsset.JPG

UI Canvas

Create 2d> canvas set screen size as 16:9. Apply camera to canvas. Pixel perfect. Scale with screen size. Graphic Raycaster allows for user to click on UI. Create child to the canvas such as a panel. Go to 2d view to resize canvas 


 

Initial Ideas, Research & Inspiration

Playing with Unity

Unity allows me to create almost anything I can think of, which makes me think I should avoid a cliched 3D space to explore. I can play with physics, scale and sound. One of the first things I thought of was a scene that requires the user to jump into a bottomless pit, and the entire environment is experienced while falling.

Tracey Emin- ‘Everyone I Have Ever Slept With’

 

 

 

 

 

 

 

 

 

 

This slideshow requires JavaScript.

I am interested in the physical/aesthetic properties of this piece more than the concept behind it. I like the idea of the viewer entering a rich enclosed space, with an nonchalant exterior. Or like the rabbit hole in Alice in Wonderland, or the wardrobe in “the Lion, the Witch and the Wardrobe”.

Doll’s House

Sketchbook1.jpg

When I was little, I would wait until nobody was around so I could sabotage my sister’s doll house. She had populated it with scenes of sylvanian families serving eachother tea, reading bedtime stories, and any number of pleasant activities. I would stage fight scenes, with the dolls heads breaking through the windows, or make the mother serve the family the baby doll for tea.

I thought this would make an interesting environment. The user explores the doll house at the scale of a doll and wanders through the house finding the horrific scenes that I had made.

The issue with this idea is the sheer amount of modeling I would need to do. Perhaps, I could make certain areas of the house inaccesible so I would only need to model the house and the rooms inside. The bedroom that the dolls house is in could just be a skybox of a photograph. I would only need to model the front of the house.

SONY DSC

 

Gone Home

 

The video game, “Gone Home” has the player explore an empty house, piecing together items like journal notes or concert tickets to work out the story. I’ve played this game and it was painfully dull. The most interesting aspects of the game are the creepy atmosphere (I’m unsure if its intentional), and the detatchment the player has while exploring the house- they are not the main character, they are the player themselves.

The Stanley Parable

“The Stanley Parable” is a far more interesting game. The game confronts the theme of choice, explored through the conflict between player and author. The game has many endings, offering the illusion of choice but one must remember that each choice has been maticulously planned and scripted.

lhroq

The game is set within an office building. Although it sounds mundane, The Stanley Parable really plays with its environment, with the game often taking absurd turns. This could be an interesting path to look down. The dull and repetitive environments draw attention to any anomaly- asking the player to investigate, and rewarding them for doing so.

Everybody’s Gone to the Rapture

Everybody’s Gone to the Rapture has players exploring a town in the English countryside after a disease has wiped out the population, freezing the town in time. The player follows the story through encounters with glowing orbs that turn to the memories of humans.

Aesthetically the game is stunning. It would be difficult for me to achieve an experience like this game as most of the experience is from the insane production value and immersion it creates. Although it is interesting to see how a story can be told through a somewhat static environment.

 

 

 

 

 

 

 

 

 

 


Developing Doll’s House

The user will switch between two rooms, each time they enter a room, the scene will have changed. This can be controlled by a box collider that triggers changes in the objects.

I will use Paul’s Unity example with the capsule with a first person camera and the player control script. Then I will use placeholder objects to get an idea of how the program will work. This will save the modelling until last so most of my time is spent in Unity, and I don’t get carried away with modelling.

 

I found a FPS controller in the standard assets and have decided to use that as the player. I now have two rooms, and need to trigger an event when the player enters the collision zone.2

CollisionProto01

 

I wrote a script that takes the objects original material. If the player enters the trigger zone, it will change the colour to black, then back to the original colour when the player leaves. I created this to find a way to trigger events when a player enters a trigger zone.

CollisionProto02.gif

I then adapted the code to spawn a cube when the player is in the opposite spawn zone.

 

I then created a door, with a collision box in front of it. This plays an animation that rotates the door.

DoorOpen01

Doll’s House Apperance

 

 

 

 

 

 

This slideshow requires JavaScript.

Tour01

Now I need to light the scene.

I have managed to light the two side rooms well enough. The lighting is patchy on some objects but it’s hardly noticable. However the centre room won’t allow to be lit by baked lights. I think it is because the normals on some faces are the wrong way round. I tried to change the material but I just completely broke the object.

BrokenTexture.JPG

Here is how the scene looks at the moment.

Lighting

For some reason I quite like the magenta of the broken textures but they don’t fit into the context so I will fix it.

I remodelled the original room and there are a couple of problems to fix.

 

 

 

This slideshow requires JavaScript.

A couple of faces on the stairs and banister glitch. And the wall is too short for the other rooms.

I fixed the models to the best I can get them without spending too much time.

Layout.JPG

Now I need to model and animate the furniture.

CeilingLight

Cupboard

The starting room is just about finished. The objects just need to be textured.

Tour02

I will begin to model objects for the other two rooms.

Kitchen

I modelled a couple more objects and placed them in the scene. The lighting looks a bit weird but I like the effect so far. I will have to mess up the scene with just these objects. Rather than the dolls as they will be far too difficult to model.

I discovered why the lighting was fragmented on many of the imported objects. I didn’t use the scale from the Maya file but instead scaled it up manually. I think this scaled the maps too, making them all overlap with one-another giving a strange effect.

Room01.JPG

I turned off the lighting from the skybox and it has changed the entire lighting of the scene. At least it has stopped some of the fragmented lighting. I replaced the lightbox with a copy of the living room. I was originally going to use photographs of my own room but realised it would look out of place.

Skybox

I also added a radio that plays classical music.

Final Model

I now need to add colliders to the objects and texture them. Then I can begin scripting.

Materials

Textured

I added materials to all of the object. I’m happy with the result. The materials are just solid colours however, I find it compliments the simplicity of the models.

Scripting

I have already scripted a door opening animation, now I need to make it close once the player has left the room. I can do this by making the animation play in reverse once the player has left a trigger zone.

I also need to find a way to make the other room change every time the player leaves the room. This can either be random- would allow for this to be repeated infinite times but unpredictable results, or it the transformations can be scripted, this would give reliable results but would limit the number of times it can be repeated.

The door now closes once the player exits the room. However, the door will wait the amount of time the player was in the room before closing. I need to find a way to pause the animation after it completes.

I have managed to get the door to play the animation when the player touches it, then close itself after the player leaves. I can’t get the door to open again after the user has left once so I have just turned the box colider off so the player can pass through.

dooropenDoorClose.gif

DoorCode.JPG

I wrote code that gave the objects in the room a random x and z translate and a random y rotation. After a couple of time entering and leaving the room, the objects would begin to leave the room.  I rewrote the code so it would move to a random position, then return to normal and do this forever.

RoomChange.gif

Now I just need to apply this code to the other room.

After adapting the code to fit the other room. It works.

 

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s