Saturday, April 29, 2017

Unreal Engine: Creating AI Behavior Part 2

Now Do Something

In Part 1, we setup an AI Behavior Tree for our enemy character, based on the state of a Boolean variable we called isChase. The variable was configured in AI Blackboard, and based on whether or not it was set to true, the character would perform different tasks. With the behavior tree ready to go, we will now setup the logic for the tasks the character will perform, as well as the logic to change the value of the isChase variable and thus, the characters state. When isChase is false, the default state, the enemy character will patrol the area. When isChase is true, the character will pursue the player.

Setting Up the Enemy Character

In the last post we created a new character by adding a new Blueprint Class based on the default Character class. We then set it to use the SK_Mannequin skeletal mesh and the ThirdPerson animation blueprint. We will need to add a few additional things to the character to make our task logic work properly. First we will add a new Boolean variable called isSprinting. Remember we called the enemy character AI_Patrol. Open the AI_Patrol blueprint by double-clicking it in the Content Browser. From the left pane select + sign next to Variables; a NewVar_0 variable will appear and its attributes will display in the right pane. Change the name to isSprinting and make sure the type is set to Boolean. We will use this variable to change the character's walk speed; normal walking pace when patrolling and running pace when chasing. Lastly click the small icon to the right of the variable to set it to public. You will know it is set when it looks like an opened eye, instead of a closed one. 

Next we are going to give the character "vision", in a manner of speaking. From the top of the left pane select +Add Component, and in the search bar type Box Collision. Make sure you are in the Viewport tab, and you will see the new box appear in the Viewport. Name the box collision AI_Vision. This box will act as the enemy charcater's view and will detect the player character. Essentially, when the player character collides with this box, the enemy character can "see" the player. Move the AI_Vision box so that it does not intersect with the enemy character mesh or capsule component. I.E. move the box slightly in front of the character mesh. This will prevent and error in Unreal that occurs using this particular AI method. Now scale the box to give the enemy character a reasonable amount of vision. In my case I have the scale settings of the box set as follows:

X Scale: 8.5
Y Scale: 7.5
Z Scale: 1.0

I feel this gives the character a realistic amount of peripheral and forward vision. You may want to tweak this settings based on your particular game. If the scale is to short or narrow, the enemy character may never see the player, to large of a scale and it may see the player from a unrealistic distance. The collision box will not be visible during game play. 

AI_Vision Collision Box

Changing States

Now that we have the necessary variables and "vision" we will create the logic to change movement speed and the enemy character's state. In my case I want to character to move at a walking speed when patrolling to give it the illusion that it is carefully patrolling the area, and then when it sees the player character I want to run as it will be chasing the player. 

Move to the Event Graph tab in the AI_Patrol blueprint. Right-click and add Event Tick. Next right-click and add a Branch. Connect Event Tick to Branch. We will branch based on the state of the isSprinting variable. From the left pane drag the isSprinting variable into the Event Graph. You will be presented with two options, Get or Set. In our case we want to Get the value the of the variable, so select Get. Connect it to the Condition node of the Branch

Drag a new connector from the True node of the Branch and in the search box type Set Max Walk Speed; you may want to have Context Sensitive unchecked for this. Set the Max Walk Speed to your desired speed. This value is for when our enemy character is running. The default max speed for a third person player character is 600. So if you want the enemy to be faster than your character, set it higher than 600, lower if you want it slower. Now drag a new connector from the False node of the branch and again type Set Max Walk Speed in the search box. This time we are setting the speed for when the enemy character is walking. I have found that a speed of 150 aesthetically looks like a normal walking speed in game, but adjust as you see fit. 

Lastly, right-click and add Get Character Movement to the event graph. Connect to the Target node on both Set Max Walk Speed events.
This will now set the walk speed of the enemy character based on the isSprinting variable. You may want to Comment the section for organizational purposes. 

Walk Speed Logic

We will need to create another set of logic for the enemy character for its vision. Again we are going to use the collision box we set up earlier to tell the enemy character when it "sees" the player character. In the left pane right-click on the collision box, remember will called it AI_Vision, and select Add Event and then choose OnComponentBeginOverlap. We are going to the set this to change the value of the isChase variable from Blackboard, and thus change the enemy character's state. Drag a connector from the top node of OnComponentBeginOverlap and type Blackboard Set Value as Bool and add it. Check the Bool Value box. This will set the value to true. Now we need to tell it what variable to change. Right-click and type Make Literal Name and add it. In the text box next to Value type isChase, the name of our Blackboard variable; this must match exactly. Connect Return Value to Key Name in the Set Value as Bool event.

Now we will create another event for when the player is out of the enemy character's vision. Again right-click the AI_Vision collision box in the left pane, select Add Event and this time choose OnComponentEndOverlap. Again we will add a Blackboard Set Value as Bool event and connect it the the top node of the OnComponentEndOverlap event. This time make sure that the Bool Value box is unchecked. Also connect the Key Name of this event to the Return Value of the Make Literal Name event.

Lastly we need to target both overlap events to the enemy character. Right-click and type Self in the search box and choose Get Reference to self. Drag a connector from Self and type Get Blackboard and select the Get Blackboard function. This will connect Self to the Target node of the Get Blackboard event. Finish by connecting the Return Value node of Get Blackboard to the Target Node of both Set Value as Bool events.

Vision and Character State Logic
In a nutshell, if the player character overlaps the box collision of the enemy character, its changes the value of the isChase variable to true, which based on the AI Behavior tree will make the enemy character chase the player at running speed. When the player character does not overlap the collision box the enemy character sets the isChase variable to false and the enemy performs the patrol task at walking speed.

Setting Behavior

At this point all logic and necessary components have been added to the enemy character and it can change it's state based on the overlap condition of the collision box we created. We still need to tell the enemy character to use the Behavior Tree that we created in Part 1. To do this we will create a controller. 

In the Content Browser click Add New, select Blueprints, Blueprint Class and in the search box type AIController and then select AIController from the results. Give it a descriptive name, in my case I called it AI_Cntrl. Open the blueprint for the new controller by double-clicking it in the Content Browser. We only need to setup some very simple logic.

In the Event Graph right-click, search and add Event BeginPlay. Drag a connector from Event BeginPlay and type Run Behavior Tree in the search box and select it. You will see that the Run Behavior Tree event automatically targets the built-in AIController. Lastly under the BTAsset option click Select Asset. As we have only set up a single Behavior Tree so far it should be the only option in the drop down. In our case we called ours AI_Behavior, so we select that one. I imagine in a game with multiple different enemy characters you may have multiple Behavior Trees. Thus just make sure you are selecting the appropriate one for the particular enemy character. That is all we need to tell the enemy character to use the Behavior Tree as soon as the level starts.

AI Behavior Tree Controller

Tasks

Our next step is to create the logic for the patrol and chase tasks that the enemy character will perform. I will demonstrate these a little differently than I have before as I will show the blueprint first and then explain the logic behind it. We will start with the Chase task as it is a little simpler than the Patrol task. 

First we need to create the tasks. In the Content Browser select Add New, Blueprints, Blueprint Class. From the search box type BTTask and select BTTAsk_BlueprintBase. Name the first one AI_Chase. Create a second BTTask_BlueprintBase class blueprint and name this one AI_Movement.

Chase Task

The AI_Chase task blueprint will only have an Event Graph. Open the blueprint by double-clicking it. See the figure below for the components.



The first component is Event Receive Execute. The Behavior Tree will initiate execution of the Chase task. We set the Execute task to send the desired task to the AI_Cntrl controller we set up earlier and connect them as shown. To add the Cast to AI_Cntrl node, right-click and type Cast to AI_Cntrl in the search box; works best with Context Sensitive unchecked. Next add the Get Controlled Pawn function and Cast to AI_Patrol  and connect as shown. Thus far we are telling the task to be sent to the AI controller we created and then we are having that controller tell our AI_Patrol character to perform the task. Since we are chasing we want our enemy character to run. So we add a Set isSprting event by right-clicking and typing it in the search box. Check the isSprinting box. With this variable set to true our enemy character logic will change its walk speed to running speed. Finally we need to set a target for our enemy character to move to, in this case our Player Character. We accomplish this by adding a Simple Move to Actor function. Connect the Controller node to As AI_Cntrl in the Cast to AI_Cntrl node to tell it what controller to send its destination to, and then add and connect a Get Player Character node to the Goal of the Simple Move to Actor node. So the Simple Move function tells the controller, which controls our enemy character, to move to a destination, which in this case is the Player. 

You may notice that the Get Player Character has an option for Player Index. This option, if I am not mistaken would be used primarily if your game has multiple player controlled characters, such as a multiplayer or co-op game. In this case we might set the index to a higher number to target a different player character. Since this game is single-player we can leave it at the default of 0. 

Patrol Task

The AI_Movement patrol task uses much of the same logic as the chase task with a few exceptions. The exceptions are due to a delay I added before the enemy character moves to its next patrol point and the fact that the next patrol point is chosen at random from within a certain radius of the enemy character. The delay is purely for aesthetics. 


As you can see most of the same base logic is used starting with Event Receive Execute which is initiate from the Behavior Tree, Cast To AI_Cntrl with Get Controlled Pawn and Cast to AI_Patrol and setting the isSprinting variable. I will focus on the extra logic for this task.

As I want to Enemy Character to pause before moving to the next patrol point, I have added a Delay function between Event Receive Execute and Cast to AI_Cntrl. I have the enemy pause for a random interval between zero and three seconds. To accomplish this I added a Random Float in Range option and set min value to zero and max to three and connect it to the Duration option of the Delay function. You could set the duration to a fix period of time, in which case you would not need to the Random Float in Range option. From there it connects through to Cast to AI_Cntrl. 

The logic remains the same through Set isSprinting. Here I have the enemy character choose a random point within a radius of 3000 units from its current location. That random point will be set as the next patrol point it will move to. We are going to use the Blackboard variable Dest that we created in Part 1 to set the location.

From isSprinting add a Set Blackboard As Vector node. From the Key option drag a connector and then type Dest in the search box and select Get Dest Loc. From the Value option drag a connector and search for Get Random Reachable Point in Radius and select it. Set your desired radius in the Radius text box. We will need to tell it what the center point of the radius is, which in this case will be the current position of the enemy character. From the Origin option drag a connector and type GetActorLocation is the search box and select it. It will connect to the Return Value option. Then connect the Target option of GetActorLocation to OwnerActor from Event Receive Execute. Lastly connect Return Value of Get Random Reachable Point in Radius to the Value option of Set Blackboard Value as Vector. So the destination point is chosen from a random location with 3000 units of the enemy characters current location. Finally add a Finish Execute function at the end. We do this because the patrolling tasks is essentially a loop that the enemy character continues through while the isChase variable is false. Each time through the loop the character starts the task over choosing a new random point to move to.

Assign Tasks

Our final step in the whole process is to link the tasks to the Behavior Tree. Open the Behavior Tree blueprint by double-clicking it in the Content Browser; we called ours AI_Behavior.

Remember we have two Blackboard Based Condition Sequences. One for isChase Not Set and the other for isChase is Set. Right-click and expand Tasks from the pop-up menu. Select AI_Movemnent from the list. Connect this to the isChase is NotSet sequence. Right-click again and expand Tasks, this time select Move To. In the properties of Move To in the right pane make sure that the Blackboard Key option is set to Dest. Also connect this to to the isChase is NotSet sequence. Now our task for patrolling is set it the Behavior Tree.

Right-click, expand Tasks and select AI_Chase from the options. Connect this to the isChase is Set sequence. We do not have to add a Move To option to this sequence as the AI_Chase task sets the target itself. 

Our AI behavior is now complete. When placed in the level our enemy character will have a default state of patrol, as isChase is initially set to false. When the level starts the enemy character will begin patrolling to random points. If at any point during the level the player character collides with the enemy's box collision, the enemy character's state changes to Chase, as the isChase variable is set to true, and it will begin chasing the character.

I have not yet added any logic to do anything if the enemy character catches the player. In an actual game catching the player would inflict damage or something along those lines. I may delve into that in a future post. The main focus of this series was to simply show how to program multiple behaviors into an AI character. As always I hope that you enjoyed this post and continue to check back in the future as I continue on my journey to become a game developer. Thanks for reading.

- End of Line

Sunday, April 23, 2017

Unreal Engine: Creating AI Behavior Part 1

When You Need AI in Your Game

Unless a designer is creating a game that is strictly multiplayer, with no non-player characters whatsoever, they are going to need to design some sort of intelligence to control NPCs. This can range from simple background characters moving around the scene to provide some ambiance to enemy characters intent on stopping the player from achieving their goal. Unless the intention is to place statues in the game, AI will need to be addressed by the designer. 

Simple Behaviors

In some cases, AI can be very basic. Such as the example stated above where NPC characters are simply moving around the scene. Perhaps a designer has a scene in a small town and wants to add some villager characters to move about in order to make the scene appear more realistic. In this case the NPC characters can be programmed with some very basic logic to have them move around the village. Essentially these characters will have only one function, so only a single function needs to the programmed. The designer could use the Blueprint Based Task (BTTask) node in Unreal Engine to create the movement for the characters. There are several ways to design to logic for movement. My personal solution would be to have the character select a random location within the certain radius and then set that location as a destination for the character to move to. I will provide detailed the logic for this type of task in Part 2.

Complex Behaviors and States

To have an NPC perform more complex behaviors, a designer will have to program much more logic. As an example, say there is an enemy character in the level that has two functions, first to patrol an area and second to attack any player characters who come within range of their vision. Thus, at different times the enemy character will be doing different things. How does the enemy character determine what it should be doing? 

This is where player states and behavior trees come into play. With our enemy character there will be two states it will be in at any given time, either patrolling or attacking. Based on what "state" the character is in, the behavior tree will tell the enemy character what tasks to perform. The designer will need to set the enemy characters default state, and then set conditions to change the state of the character in order to change its behavior. 

Enemy Patrol Character Example

We will need a few prerequisites for our enemy character to move around the level. Most importantly a NavMesh (Navigation Mesh Bounds Volume). For any object to move in Unreal Engine, its needs to know where it can move. This is provided by placing a NavMesh into your level. For the example, I assume your have already created a level and are ready to place characters. In this example I will be using an outdoor level I created for my 3D Design class. 

From the left pane, select Volumes and scroll down to Nav Mesh Bounds Volume and drag it into your level. Once it is in your level, scale it to the size that is needed. You will want to make sure that the volume intersects with any surface you want characters to be able to move across. So you will want to move it slightly below the surface. Also make sure that the volume is tall enough for your characters height. In my case the enemy character uses the standard third person character skeletal mesh and only walks or runs. So my NavMesh only needs to accommodate the height of the enemy character.

NavMesh in Unreal Engine
You can use multiple NavMesh volumes in a single level. In the level shown I have used three NavMesh volumes to ensure that my enemy characters don't accidentally tumble into the gorge that runs through the middle and will only cross on the bridge. Using multiple volumes also allows you to prevent NPC characters from going to an area where you don't want them to be. Hitting P while in the viewport window will display the NavMesh volume and ensures that it is intersecting the surfaces you want, as shown by the green color. Normally the volume will be hidden from view. Hitting P again will hide it from view again. 

So now that the engine knows where characters can move, its time we set to creating some. I will call our character AI_Patrol and create a new Character Blueprint for our enemy. I set it to use the ThirdPerson skeletal mesh and movement animations included in the Third Person template in Unreal Engine. I will need to add some additional components to the character which will be shown in Part 2.

To start working on the enemy character's behavior we are going to use Unreal's AI Blackboard to create some variables that we will need. From the Content Browser select Add New select
Artificial Intelligence and then select Blackboard. Open the blueprint editor for the Blackboard by double-clicking it in the Content Browser. I am going to create three new keys:

Dest - a vector variable which will be used to set the character's destination

isChase - a Boolean variable which will be used to set the enemy character's state

SelfActor - an object variable used to set a target object

Blackboard Variables
To create the keys select New Key from the top and then select the type of variable from the drop-down name and give it the appropriate name. For the Dest and isChase variables, the type of variable and name is all that is needed. For the Self-Actor variable, we also need to make an additional change the base class option. After naming it, expand the Key Type setting in the right pane and change the Base Class from Object to Actor.

Next we will create the Behavior Tree, which will tell the enemy character what to do based on its current state. From the Content Browser select Add New select Artificial Intelligence and then select Behavior Tree. Open the blueprint editor for the Behavior Tree by double-clicking it in the Content Browser. The base behavior tree will only have a root node to start. 

We need to give it some decision making ability. Add a Selector by right-clicking and typing Selector in the search box. Add it to the blueprint and connect it to the root node by dragging a line between them. The selector is what we will branch from to make our decision on what behavior to perform.

We will now add a Sequence for each of the behaviors. Right-click and type Sequence in the search box. Add two sequences and connect each to the selector. The sequences will be based on the isChase variable from Blackboard. To tie these sequences to the Blackboard variable we add a Decorator to them. Right-click on one of the sequences and select Add Decorator and choose Blackboard from the pop-up menu. You will now see an additional box inside the sequence. Click on Blackboard Based Condition in the sequence. Options for the Blackboard Condition will appear in the right pane.

The isChase variable we created in Blackboard is what we will use to set the enemy character's state. The character will either be chasing or not chasing. Based on these states the character will perform a defined task. For the first sequence we will set tasks for when the enemy is not chasing. Set the following settings:

Flow Control
Set Notify Observer to On Result Change
Set Observer Aborts to Self

Blackboard
Set Key Query to Is Not Set
Set Blackboard Key to isChase

This is basically setting this sequence to perform the attached tasks when the enemy's isChase state is set to false.

On the second sequence we will set it to perform attached tasks when the isChase is set to true. Right-click the second sequence and choose Add Decorator and select Blackboard. Click on Blackboard Based Condition in the sequence and set the following settings:

Flow Control
Set Notify Observer to On Result Change
Set Observer Aborts to Self

Blackboard
Set Key Query to Is Set
Set Blackboard Key to isChase

So now we have a decision branch to choose what the enemy character does when the state of the character changes; one task if isChase is set to true, and another if isChase is set to false.

Behavior Tree Based on Blackboard Conditions

You may notice in the figure above that the tree has tasks defined below the sequences. These are Blueprint Based Tasks I have created for our enemy character which I will detail in Part 2. The AI_Movement task tells the enemy character to patrol an area by selecting a location within a certain range of the current location and then moving to that location. The task also adds a delay before moving so that the enemy character appears to pause before moving to next location; as though it is scanning the area. The AI_Chase task tells the enemy character to pursue the player character if they come within range of the enemy characters vision. Logic for both of these tasks will be detailed and will show how the enemy character's state changes based on conditions set in the tasks. 

As always I hope that you enjoyed this post and are looking forward to next. 

- End of Line



Sunday, April 16, 2017

Greyboxing

I imagine that every game starts with an initial idea in a designer's head. I also imagine that the path the idea takes to becoming a full fledged game varies from designer to designer. Be it a solo indy game or a triple A title from a big publisher, eventually that initial idea has to take shape in the form of a playable game. However modest or ambitious the start, a designer is at some point, faced with creating the physical world for the game. Prior to starting my journey to becoming a game designer I only imagined what that involved. As I have progressed on my journey I have been introduced to some very effective methods for bringing a game to life; once such method is called greyboxing.

Greyboxing

Greyboxing, some also call it grayboxing or blueboxing, is basically blocking out an environment with simple geometric shapes in order to get a level's layout down and test playability quickly without worrying about textures, materials or precise architecture. The term greyboxing comes from the fact that when you place basic geometrical shapes without assigning textures they have a basic grey color or a grey checkered pattern on them. At least that is the case in Unreal Engine. Other tools may use different colors, hence the multiple terms for the method.

Greyboxed Interior Level in Unreal Engine 4
By greyboxing a level initially the designer can determine how well the level flows, if the scaling is correct, and try out different game elements without wasting a lot of time. Imagine laying out an entire level, applying textures and materials, tweaking lighting only to find out when you play test that some part of the level is not working the way is should. By greyboxing you are able to work out those types of kinks beforehand.

Benefits

Some of the many benefits of greyboxing:

  • Allows for quick changes to a level's design without concern for effecting elements such as lighting
  • Provides a quick method for determining scale
  • Provides an early blueprint for the level to allow other team members to begin asset creation
  • Provides a test environment for game play elements and mechanics
Having been introduced to the method I attest that it is a very effective method when first building an environment. Even for those who have laid out a level on paper prior to starting their build this method provides a great 3D sketch of the environment.

Greyboxing Example

Below is an example of greyboxing a basic structure in Unreal Engine. In this case I began with the third person template in Unreal Engine. The beginning template structures have been removed with the exception of the floor.


I start by dragging a Geometry box brush into the scene to make a wall and then scaling it the approximate size I think I need. If you want to make openings in a surface at some point, make sure you use Geometry brushes in Unreal and not Basic brushes. With Geometry brushes you can make them additive or subtractive. Additive means it adds the geometry to the scene, like our wall. When I make a doorway through the wall I use the same box brush, but I make it subtractive, so it removes the shape from the wall to provide the opening. Below I have made a wall with a doorway, and then duplicated both to make the wall on the opposite side.



At this point I have play tested once to make sure that my doorway is scaled properly to let the player through and also to ensure that is appears proportionate to the structure I am creating. Next I add the remaining walls again using a Geometry box brush and scaling them to the appropriate size and moving them into place. And now we have a basic building with four walls. 


Time to add some windows using a subtractive box brush. In this case my windows will be the same size. Once I size the first window I simply duplicate it and move into the position I want and then repeat. I would suggest that if you are going to be duplicating brushes in Unreal, give them descriptive names. It will make them easier to find in the Content Browser later if you decide you want to make a change.



Lastly I have added a roof for our building with an overhang and some support pillars.

Exterior View

Interior View

So as you can see we have created a greyboxed building in relatively short order. Quick play testing has ensured that the scale is appropriate and that our player can move through doorways. At this time we could start adding some game play elements or adding some interior lighting. In my opinion it is better work on lighting once you have started applying textures and materials as they will have some effect on lighting color.

Greyboxing this building allowed me to quickly get my scale down for the structure and get a sense of size. If I was working as part of a larger team, this would provide them with an accurate model of the structure so they could begin working on architecture and all the "pretty" things. Hopefully this quick demo has shown how useful a tool greyboxing can be.

- End of Line

Friday, July 8, 2016

Learning to Make Video Games: One Geek's Journey Part 2

Back on Track

So after a little bit of a hiatus I am back on my journey to learn to create games. This past semester in school I took a break from the core classes to finish off my last general education requirement. From this point forward it's all programming and design classes. I have 10 classes left to complete my degree and will be taking 2 classes each semester. This coming fall I will finally start touching on programming and scripting for games. The following semester I am really looking forward to as I will finally get into 3D game design and programming. During past few months I have continued my self-paced study of C#. As you may recall this is inline with my focus on utilizing Unity for creating games. I have been using the course from Microsoft Channel 9 on C#. I am more than half-way through the modules at this point, though I have not been as diligent as I would have liked in my studies. However, my daughter has graduated high school and just yesterday left for Navy boot camp, leaving my wife and I as empty nesters. So this leaves me with more free time to jump back in full steam. 

Fundamentals

The Channel 9 course that I have been using was developed by Bob Tabor from LearnVisualStudio.NET. Bob has the modules laid out quite nicely and one lesson flows into the next, and builds upon the last. Often in a lesson Bob will touch on subject or demonstrate code that won't be fully explained, but not without purpose and it is usually set up for a future module. As the intent of the course is to provide you with a groundwork of the C# syntax, this course does not directly apply to game programming, but I do feel I am getting a good introduction to C#. 

I will admit that I am, at times, finding the examples in the lessons a bit pedestrian. However, I feel that the lessons are paced appropriately for an absolute beginner. For myself, I have found that it helps me to go a little bit beyond at the end of each lesson. By that I mean that I take it upon myself after each lesson to augment the code that I just learned and add some new functionality to the program that was just demonstrated. I am challenging myself to go beyond rote memorization and see what I capabilities I can extend on my own. Frequently as I am going through a module, I will already start thinking about what else I can do with the code that I just learned. I try not to stray too far off the reservation as I know the lessons are building upon one another. I do feel though that playing around the code after a lesson helps me retain what I just learned a bit better.

Visual Studio

For the lessons I am using Visual Studio Community 2015. It is a fully featured IDE (integrated development environment), and provided completely free by Microsoft. To this point much of the lessons have created console (DOS) applications and I am fairly certain the course will not be touching on the visual part of Visual studio. And to be perfectly honest, I am completely okay with that. For me it's about learning the code, not about creating user interfaces.  

Visual Studio provides the necessary components to code in C#, Visual Basic, F#, C++, HTML, Python, Javascript and many others and allows you to create applications for just about any platform. It is also completely extensible with over 1,000 extensions available. Anyone can download Visual Studio here. For individual programmers it is completely free and you can create your own paid applications with no licensing fees or royalties. For for-profit companies, license fees may apply. 

The download can be up to several gigs depending on what options you choose during installation. Once it is installed you have the option of linking it to your Live account. I recommend this option if you are using Visual Studio in multiple locations. I my case I have it installed on my home PC, laptop and work PC. Linking it to my Live account syncs any changes I make to the interface across all three systems. I personally prefer a dark background with light lettering. And as a geek who is frequently rebuilding his own PCs it is nice to have my settings imported automatically if I do a new install of Visual Studio on a new machine. 

Another useful customization I have made is to change the default save location for my code. Through my business I have an Office 365 account which includes 1TB of OneDrive storage. By changing the default save location to my OneDrive folder, any new or modified programs I am working on will automatically be copied to my other systems. This has been extremely useful if I am working through a lesson and have to stop mid-stream. I can easily pickup right where I left off on any one of my PCs or my laptop. Granted not everyone has a terabyte of cloud storage, but you can set the default location to any folder that you like so you can utilize Dropbox or Box to accomplish the same thing. 

Next Steps

I know I said this in the last post, but I intend to post more frequently now that I find myself with more free time. Looking a head a little bit, my plan is to complete the fundamentals lessons over the next week to two weeks. The new semester will be starting up in late August so that will leave me a little bit of a gap to fill and I want to be working on something on a regular basis. Currently I am debating whether I want to jump into a Unity Course on Udemy or start on a C++ course. Logically the next step would be to start the Unity course as it will build upon my foundation of C#, as Unity uses C# as it's scripting language. The only reason that I am considering jumping into a C++ course is that in the Winter semester I plan to take an Advanced C++, a requirement for my degree. I had taken and passed the introductory C++ course 15 years ago when I first started taking classes. However, I have forgotten everything I learned about C++. I still get credit for the C++ class and I am not required to take it again, but I cannot jump into the Advanced class cold. My plan has been to take a C++ refresher course on Udemy before the Winter semester.

So I could get straight into Unity and keep building up my C# skills, but that would mean I would be taking the Udemy C++ course at the same I am taking  two courses in the Fall semester. I know for some this does not seem like a lot, but for this middle-aged man running his own business and taking two courses a semester is a full load. Well I guess step one is finishing off the C# fundamentals course, so I will concentrate on getting that out of the way, then decide. Thanks for reading, and I hope that you are enjoying my journey and that maybe it helps you in yours. Until next time. 

--End of Line






Monday, November 23, 2015

Learning to Make Video Games: One Geek's Journey Part 1

Humble Beginnings

For a very long time I have wanted to make video games. Not just as a hobby, but also as a profession. I am starting this journey in earnest now and I am writing this to share my experience in the hopes that others may benefit from it, but also for myself as sort of a journal as I progress.

First a little background. I began my journey after high school, taking programming classes at a local community college. I was on a path to get an associates degree in Computer Science, with a focus on programming. Life, as it turns out, had other plans for me. After completing a few semesters I happened to find the love my life, my wife, and very soon after and quite unexpectedly, she became pregnant with our first child. So I decided to put my plans on hold in order to provide for and be there for my family. Having always been a geek and quite proficient in networking and all things PC, I had already been working as a junior system administrator. So I worked to get a few more certifications under my belt and continued on that career path up until very recently.

Fast forward 20 years. My children, two, are both grown now, my son 19 and in the Navy, my daughter 17 and completing her final year of high school. She also joining the Navy after high school. My wife has found a career that she loves and is very happy with. I have given up the corporate career and now own my own small computer repair and managed service business. While not a lucrative as my former jobs, I am very happy doing it. Still an avid gamer I have decided I have reached a point where I can pursue my original dream of making video games.

Old Dog, New Tricks

So at the tender age of 40, I am taking a two-pronged approach to achieving my dream. To my surprise my community college still had all my records on file, even though I had not taken a class in over 14 years. As it also turned out, they had a new degree path available, Game Design and Development. As most of the classes I had taken previously were general education courses and a few entry-level programming courses, almost all of my old credits still applied. Awesome! So the first approach is getting my degree in the Game Design and Development. Currently I am in the early core courses of the degree so I haven't gotten into programming courses just yet, mostly design concept courses.

My second approach will be self-paced learning. I have purchased a few courses at Udemy on creating games with UnityI am also utilizing some free training courses from Microsoft Channel 9 on the C# programming language. After considering both Unity and Unreal Engine to begin creating games, I settled on Unity. I chose Unity largely for two reasons. First, it appeared to me to have a slightly lower learning curve than Unreal Engine. I guess I will find out if I am correct. Second, I was exciting by the possibility of cross-platform development. As C# is used by Unity for scripting, I am also utilizing the C# courses from Microsoft simultaneously.

Unity3D First Impressions

So this week I downloaded and installed Unity3D 5 Personal Edition. I have not started on the Udemy course yet, but I wanted to get prepared and familiarize myself with the interface and options. So after installing I began with the Interface and Essentials tutorials on the Unity website.

For starters the tutorials are laid out well and ease you into using the interface. Each tutorial expands on the last and explains more and more of the interface options. Upon opening Unity for the first time, the interface can be a bit overwhelming as there are several panes, tool bars with a myriad of options in each. The tutorials will help you get a grasp of what each pane does and how to utilize them.

When first starting a new project, assuming that you have chosen a 3D project, you are presented with fours panes; the Hierarchy pane, Scene pane, Project Pane, and the Inspector pane. Anyone who has used Unity 4 versions, will notice that this is a slightly different layout, version 4 had five starting panes.

The Scene pane is where you visually construct the game and can manipulate objects in 2D and 3D. The Hierarchy pane lists all objects in the scene in alphabetical order and in hierarchical order to show parenting. The project pane shows all assets you are currently working with, in one place, giving you quick access to everything in your game. The inspector pane is context specific and will show the properties of whatever object, asset or settings panel you have selected. In previous versions of Unity the Game pane was a separate fifth pane in the default view. It now shares the Scene pane as a separate tab in the same pane.

At the top, center of the screen are Play controls. This allows you to test your game while in the engine. You have the option to play test in real-time, pause or frame-by-frame in the Game view. The top-left toolbar allows you to navigate the Scene view and manipulate objects visually. The top-right tool bar are the Layers and Layout drop-down. The Layers drop-down allows you to add or hide layers on content. The Layouts drop-down allows you to select different layouts for the Unity interface. For those of you more familiar to the 5 pane view from previous versions fear not, it is one of the layout options from the drop-down. You also have options to save or delete a layout, so presumably you can create the layout you are most comfortable with and save it. More on that in a bit.

Being a complete novice, I am assuming that a majority of time will be spent in the Scene pane. The Scene pane initially opens with a completely open space with a grid pattern floor and simple sky box scene. It has a single light source illuminating the scene and a single camera view. The four top left tools buttons correspond the  Q, W, E and R keys, provide a quick keyboard shortcut, in combination with a right mouse hold, to change the way the you move the view in the Scene; i.e. up, down, left, right, pivot, pan and tilt. This will also be how you place, move and scale objects in the Scene view.

So having gone through some of tutorials and actually starting to use the interface I can say that I like the default layout for the most part. Having watched the tutorial which showed the 5 pane view, where the Game view was a separate pane, I think that having it a tab in the same pane as the Scene view is a good choice. The frees up valuable screen real estate. While I love that you can play test in the engine without having to compile, I think the Game view does not need a separate pane that is always in view. Having it as a tab in the Scene pane gives you quick access when you want to jump in a play test, without taking up 20% of the screen.


Unity 5 Interface

The four pane view in my opinion is optimal. You can re-size any of the panes to your liking. For me, I thought the hierarchy pane is a bit wider than need be. Also, I think that the Inspector Pane is a bit taller than needed. Personally I would like the have the Hierarchy Pane above the the Inspector pane on the right side, providing more room for the Scene Pane. That's where I did have some issues. While I could detach a pane and move it to a new part of the screen, I could not figure out how to fix it into the new position, it simply remained as a floating window. After fumbling around I was able to get the pane snapped into the position that I wanted it. You have to make sure that when you grab the pane, by holding down the left mouse button, the cursor in positioned on the tab in the pane, and not the empty space next to the tab. When the cursor is on the tab it will snap into area of the another pane automatically. Like I said I did eventually sort it out, but I think that the interface should be a little more intuitive and snap into position no matter where the cursor is positioned in the pane.

I determined that where the floating pane comes in handy is with a multi-monitor setup. In my case I have dual monitors. If you undock a pane and keep it as a floating window you can position it on a different screen. You can also save it as a layout. I tested it by undocking the Hierarchy and Project panes and moving them to my second monitor. I saved the layout and then closed the Unity interface. After re-opening Unity the undocked panes opened up on my second monitor right where I has positioned them. A nice feature for those with multi-monitor setups who really want to stretch their screen real estate. 

Another useful feature I discovered in my fumbling is that on each pane you can add additional tabs, the same way the the Scene view and Game view are separate tabs in the same pane. That is when I also discovered that there are some additional views that are not in the default view; Profiler and Animation. Not sure what they are for yet, but I am sure I will get there eventually. With the tabs feature you can group views in the same pane. So if you really want to go minimalist with your interface, you can. Having the ability set the screen to your own personal preferences is an outstanding feature, even with my little gripe about moving the panes. And floating panes certainly will help those with multi-monitor configurations maximize to their heart's content.

I have yet to get into placing objects in the Scene view, but I will be doing that soon. From the tutorials I know that you can manipulate objects on each individual axis or all axes simultaneously. It does seem that manipulating objects on an individual axis can become a bit unwieldy and the objects can easily become disproportionate. I'll have more on that in a future segment.

Overall my first impression is that Unity does a good job with the interface and the default interface should suffice for most developers needs. Again, having the ability to personalize the layout to your individual liking is a top notch feature. Aside from my one little complaint I am very pleased with my experience so far.

Please stayed tuned as I plan the add segments on a weekly basis at a minimum, perhaps more frequently when I can. Thank you for reading and I hoped you enjoyed.














Monday, November 2, 2015

Augmenting The User Experience in Gaming

We live in an ever increasing technological world. Just look around and you will see a multitude of people with smart phones, tablets, laptops or in many cases all three. Technology is part of our every day lives and we rely in for many different things. And very soon, technology will change how we see the world through the use of AR or augmented reality.

What is Augmented Reality?

Augemented Reality is the use of technology to supplement the real world with sensory input such as sound, video, graphics and GPS. Essentially the real-world is modified by a computer and the surrounding of the real world of the user becomes interactive and digitally malleable.


Microsoft Hololens
This is not to be confused with VR or virtual reality. With virtual reality the user's world is completely replaced by the virtual one. AR technology enhances the users perception of the real world by overlaying objects in a spatially intelligent way.

Hardware

Currently there are several AR devices already available or under development. Here are just a few:

Microsoft Hololens
Magic Leap
Sony SmartEyeGlass
Google Glass

While there are different ways to augment reality all of these devices have the same goal, to modify the user's perception of their surroundings. 

AR technology available today comes in the form of smart phones and handheld gaming devices. Both iOS and Android devices have AR apps and games you can currently purchase and use. Additionally both the Nintendo 3DS and PS Vita both have AR gaming apps available. While these devices show the potential gaming applications of AR, the glaring limitation is that they provide a very small window for which to view the augmented objects that are overlaid on the real-world environment.

Nintendo 3DS AR Game

The next phase of AR devices that are currently under development will take AR gaming to next level and provide a far more engaging experience for the user. HMDs or head-mounted displays place images of the virtual and real world over the user's field of view. Modern HMDs make use of sensors to detect the user's head movement in order to align the virtual information to the real world and make adjustments accordingly. This creates a far more immersive and interactive experience as the user's entire field of view is incorporated. An example of this type of device that you may be familar with is Google Glass. Currently several big name tech companies are developing their own HMDs including Microsoft, Sony, and Samsung. Recently Google was one of several venture companies that invested $542 Billion dollars in AR startup Magic Leap. 

Sample Image from Magic Leap HMD

AR Gaming

There are two reasons that I feel AR will be a big part of gaming in the near future. First, large tech companies are spending a lot of money to develop these technolgies and put them in the hands of the consumers. Two, gamers are always looking forward to the next big thing or advacement. 

If you consider that in the last 30+ years the way we play games has not really changed very much. Since the Atari 2600 the basic components of the gamer's experience have remained the same. You have the gaming device, some form of a handheld controller and a display. Now the technology has certainly advanced since the 80's. Graphics are rapidly approaching near-releastic quality, displays have gotten bigger and better, controllers have become more ergonomic and feature-rich, and gaming engines include realistic physics.

Devices like the Nintendo Wii and Kinect have moved gamers a step forward in the way that they interact with games, but not in the immersive way that AR has the potential to do. Imagine sitting down to play Call of Duty but instead of merely sitting on your coach, you need to take cover behind it. Imagine running down the hallway in your house while having to put down supressing fire to get to the next objective. See the demo of gaming on the Magic Leap below.



These are the types of interactions that AR is promising and it will fundamentally change the way we play games and enhance our experience with them. Any environment in the real world can become canvas on which games are played and the user will be able to fully interact with the phyical and virtual world. The possibility of our environment becoming the game is truly exciting and opens up nearly endless possibilities for devolpers.  Several game developers are already embracing the technology. It will be games that help foster the technology and bring it to the masses. I know I am ready for the next step in gaming experience.