Monday, April 20, 2015

Unreal Engine 4: Lift Demo v1

  After having to get Leap Motion integrated in Unreal Engine 4 I immediately jumped into learning a few new things through going to the Leap Motion website where there was an example implementation of Leap in Unreal Engine 4. Having spend some time looking at the different projects offered I felt I become somewhat familiarized with what I wanted to do. One of the things I like to do now is whenever I begin a new project, create a requirement list. To me creating a requirement list is very helpful because you can use the list as a way to debug your project further or to see if everything is matching what your requirements are for the project. For this project, I created a small requirements list.
Lift Demo
Requirement ID
Description
Status
1.1
The system shall recognize when a hand is added
Complete
1.1.1
If the system recognizes if a hand is added, the system shall set the hand mesh to visible
Complete
1.1.2
The system shall recognize when the hand is removed and set the hand mesh to not visible
Complete
2.1
The system shall be able to determine when a hand has collided with a handler
Complete
2.1.2
If a hand collides with the right handler, the system shall move the ball right with some torque
Complete
2.1.3
If a hand collides with the Left handler, the system shall move the ball left with some torque
Complete
2.1.4
If a hand collides with the back handler, the system shall move the ball backwards with some torque
Complete
2.1.5
If a hand collides with the forward handler, the system shall move the ball forward with some torque
Complete
2.1.6
If a hand collides with the top handler, the system shall have the ball jump based on an impulse
Complete
3.1
The system shall be able to change the balls material if both hands collide with one another
Incomplete
3.1.2
If two hands collide with each other, the system shall be able to change the balls collision status
Incomplete
4.1
The system shall be able to grab different objects in a scene using two hands
Incomplete

  As you can see above, I still have quite a few major aspects to still implement in the demo but other than that, I was able to get one portion working fine! So to begin the process I started off with a new project using the rolling ball template in Blueprint. Looking at some of the functionality I changed some methods, added a few functions as well as integrated the Leap Motion Controller onto the pawn blueprint. But that's not really saying much or diving in is it?

To dive into it, in the pawn blueprint of the ball I added the component Leap Motion Controller

   When I first did this, I ran into a problem. Upon starting the game, the hands would appear assuming you had your Leap Motion Controller set up. But considering the pawn is a ball that roll's, the hands would roll too. In order to prevent this from occurring I actually just attached the controller as a child of Spring Arm. Thus, the hands would not rotate. So the hands were integrated in the pawn's blueprint, but what is it doing? Nothing really. My goal was to have the hands control the movement of the ball. The way I went about doing this was creating Handlers. Each handler would determine which way the ball would maneuver when a hand collided with it. Thanks to UE4 this was simple in the Pawn's blueprint. I created five box collisions. The names I gave to these handlers were RightHandler, LeftHandler, TopHandler, Forward, Backward. All child's of Spring Arm so there relative rotation are not relative to the ball.

  After creating these new components, I placed them in the desire location close to the Leap Motion Controller. Now begins the logic! To begin with the logic I created three functions called MoveRightLeft, MoveForwardBackward, and Jump. These functions say what they need to do. Move the ball right, left, forward, backward or jump. Clicking the + sign at the top right of functions I created my MoveRightLeft function. In it was really only three statements. Setting a boolean called HandCollides to true and if HandCollides is true add a torque to the target ball. In the torque pin, I broke out the vector where I multiplied a float called RollTorque of 50000000.0 value to the parameter XAxis and plugged the value of that to the X coordinate of the vector. To end the function, I created an Input parameter called XAxis of float type.

 
  Thus ending the MoveRightLeft function. The MoveForwardBackward function was very similar. The only difference was, I use the resultant value and plugged it in the Y coordinate and changed the input paramter name to Y Axis.


  Lastly, I just needed one more function left. The Jump function. This one was already given, I just made it into a function for organization.


  Having the functions finished, I jumped back to the Event graph to get the implementation running in the game loop. Actually implementing was fairly easy, all I had to do was on each begin overlap of a handler, call the desire function relative to the name. On end overlap set HandCollides to false which disables the ball from continuing moving.



  Thus completing most part of the Demo. All I needed left was the material changing dynamically on the mesh as well as the ability to grab objects with the Leap Motion Controller. As far as it came down to dynamically changing the mesh, I was very familiar how to do it upon a key press... But not sure how to go about doing it if both hands collided with one another. To actually get the balls material to change dynamically and with it's collision I created an input event called I. My logic behind this was if the ball was not invisible, set the material to visible and set the collision response to ignore all on all objects that are dynamic. If the ball is invisible, change the material back to the original and set the collision response to block world dynamic.


  After doing this I decided to just jump into the level to see how the integration worked out and man it's so cool! My goal before actually calling this demo completed is to not only complete my requirements list, but to create the balls movement more smoother through creating a Gyro Ball. Based on the hands location in the gyro ball I want the ball's location to increase whether the hand is moving forward in the ball, forward left ect. Personally I feel this route is much cleaner. My other goal is to actually spend some time designing the level. The current level was just something I threw in to see how the functionality of the pawn works. Can't wait to release version 2 of it!!




Integrating Leap Motion in Unreal Engine 4

Currently I am taking GSP 475, phew one step closing to graduating! For this class we essentially have a eight week project where student's have the option to create something with emerging technology. For me, I decided since I have the desire to continue expanding my knowledge in Unreal Engine 4 now that 3 is slowly becoming obsolete, I wanted to do a project with Unreal Engine 4. Being up to date I am, I actually read an article from Epic about Leap Motion. For those not aware, Leap Motion is a motion tracking device that tracks hand movement. It's pretty cool and can be integrated in many software such as; Unreal Engine 4. For this project my goal essentially was to create a small game where players can maneuver a ball based on hand movements as well as have the ability to pickup objects and place them in desire locations. For this project, I decided to call it Lift. Before jumping in to how I went about developing this project, I wanted to give a brief description on how to Integrate Leap Motion into Unreal Engine 4. Here it is!


Instructions for getting Leap Motion Running


To install and be able to use this product, first you must obtain a few other software such as Leap Motion SDK, Visual Studio Community 2013, as well as Unreal Engine 4’s source code. To continue this you will also need a Leap Motion Controller.

So let’s begin with the first software.

How to obtain Leap Motion SDK:

1.      Go to the Leap Motion site.
2.      From there jump in the Developer tab and the download should begin right away. If not, hit the download link to begin the download.
3.      After the download is complete, run the installer application.
4.      Assuming a Leap Motion Controller is on hand, connect the Leap Motion Controller to your computer.
5.      In the taskbar, a Leap Motion Controller Icon should appear. Right click>Visualizer to test that the software and hardware are working properly.

There you go, you officially have integrated the working software and hardware into your computer. The next step is downloading Visual Studio Community 2013.

Acquiring Visual Studio Community 2013:

1.      Go to the Visual Studio site.
2.      Hit Download.
3.      Run the .Exe
4.      Continue following the steps guided by Microsoft visual studio to fully install it

One more list of steps and then you’re done! We now have to download Unreal Engine 4 source code onto your computer through GitHub so that you can acquire the Leap Motion Plugin in the Engine.

How to obtain Unreal Engine 4 Source code through GitHub:

  Establishing an account with Unreal Engine:

1.      Go to the Unreal Engine 4 site.
2.      If an account has been created before, sign in otherwise sign up.
3.      After signing in or signing up, go to Account
4.      In the box Get UE4 Full Source Code, right click and open in a new tab linking your GitHub account
5.      In the steps below featured on the page, click the first step’s link GitHub.com which will take you to GitHub

  Creating an account on GitHub:

1.      If an account has been created before, sign in otherwise sign up.
2.      After signing in or signing up you should have been taken to Epic Game’s page on GitHub. If not, retrace your steps back to step 4 which assuming if logged in on GitHub. You’ll be taken to Epic Game’s page.
3.      Once on Epic Game’s page on GitHub, click Unreal Engine.

  Installing GitHub:

1.      Once on the page, scroll down to Getting Up and Running where you’ll click GitHub for Windows. Assuming you have windows.
2.      On the new page open, hit the download button to install GitHub on your computer.

3.      Before continuing any further, jump back to the previous tab in Unreal Engine to your account.
4.      Hit Profile and plug in your GitHub name to sync it to your Unreal account.

  Forking and Cloning a Repository:

1.      Back to the GitHub page, at the top right corner of Epic Game’s GitHub profile, hit Fork. Doing so will create a copy of the whole source code to your account.

2.      After doing this jump into the GitHub application that you installed.
3.      Hit + > clone.
4.      From there you should see Epic Game’s where you’ll have the option to cloning Unreal Engine or Unreal Engine Tournament. Clone Unreal Engine.
5.      Choose a destination you would like to clone the repository to on your computer.
6.      After doing so a folder of the repository shall appear on the desire designated location.

  Obtaining the Source Code:

1.      Go to the folder that was just created.
2.      Run the Setup.bat file
3.      After that’s completed run GenerateProjectFiles.bat
4.      Once the files have generated a solution file for visual studios called UE4.sln should be available.
5.      Open UE4.sln.
6.      Once Visual Studio has open up, in the solution explorer right click on UE4 > build. This may take some time to build.

Once the build has completed you shall have the entire source code project of Unreal Engine now officially on your computer plus giving you access to Leap Motion Controller Plug in. But the instructions doesn’t just end here! You still got to actually plug in the plug in in a project.

  Plugging in Leap Motion into an existing Project:

1.      Open the editor through clicking Epic Game’s Launcher or through going to Engine > Binaries > WIN64 > UE4Editor
2.      Once either or is clicked, Launch the most current version of the editor you have.
3.      Next, create a new project with whatever template you desire.
4.      Afterwards, go to Window > Devices and Enable Leap Motion. Doing so will restart your project to enable it.


There you have it. Leap Motion has been fully integrated in your project! 

Monday, November 24, 2014

Creating a Game Engine: spriteContainer and Tile

  For the first few weeks in our GSP 420 course me and my group have begun the "production" phase where we're beginning to work on our specified cores; Main framework Core, Graphics Core, and AI & Collision Core based on the class diagrams we've developed for them. To begin the core that I'm in, I started off doing the spriteContainer class and Tile class. The way me and my group wanted our game engine to be was as universal as possible, so the idea I had for the spriteContainer class was to have a storage where we can place Texture2D objects in and whenever we want to grab those images we can just invoke the variable from the class. To start this off as somewhat a template I created various Texture2D variables giving them a getter and setter such as; player, enemy, block1, and exitTile.

public static Texture2D player{get; private set;}
public static Texture2D enemy{get; private set;}
public static Texture2D block1{get; private set;}
public static Texture2D exitTile{get; private set;}

  The reasoning for them having a getter and setter is simple, the name says it all. To get the value of the variable and or be able to assign something to the variable. Purposely having the setter private so only the spriteContainer class can assign the variables to something and any other class is inaccessible to doing so. After creating a couple of variables I created a function that loads the content into specified variables called Load(ContentManager content). So at the moment if we invoke these variables outside the class, nothing happens. The purpose of the Load(ContentManager content) is to be able to assign these Texture2D variables to images using XNA's content.Load. In this function I begun assigning these variables to be able to load an image by doing:

player = content.Load<Texture2D>("spriteContainer/player");
enemy = content.Load<Texture2D>("spriteContainer/enemy");
block1= content.Load<Texture2D>("spriteContainer/block1");
exitTile = content.Load<Texture2D>("spriteContainer/exitTile");

  What is happening is where assigning Texture2D variables like player, enemy and or exitTile to be able to load .png files (because we're casting Texture2D) from the folder "spriteContainer" and specifying the actual file name. So now when we're outside of this class we can just do spriteContainer.player instead of doing it the long way; content.Load<Texture2D>("spriteContainer/player"); all the time. The best part about this class is considering this is a game engine... For any game speaking, we can just continuously create new variables and add them into the Load function to store them up in the system so we can use them universally. Thus finishes the spriteContainer class....Until we make a game!

  After completing the spriteContainer class I decided to tackle down the Tile class. The purpose of the Tile class is simple...It's basically just identifying something to being a Tile in a .txt file. So this tile can be a variable from spriteContainer or just a simple string name with a collision. Now thanks to actually doing a class diagram for the graphics core I know there's going to be an association with Tile and the levelEditor class. So Tile is going to have somewhat a significance in the making. The way I thought of the Tile class was to identify something being a tile and deciding what collision type it was. So to begin this I created an enumeration called collisionType.

enum collisionType{ Passable = 0, Blocked = 1, Platform = 2, Trigger = 3}  

  The enumeration is pretty straight foward; to determine what collision type a tile has. If a tile has a collision type of passable, on a .txt file the player can pass through it. If the tile is Blocked, the player cannot pass through it. If it is a platform, the player can jump on it but keeping in mind the tile does have bounds. If the tile has a collision type of Trigger then that basically means the tile can cause an event. So this could be an item event for example. After doing this I created a Texture2D object called texture and an object of collisionType called collision. Then to be able to manipulate the size of an image/tile I did

public const int Width = 32;
public const int Height = 32;
public static readonly Vector2D Size = new Vector2D(width,Height);

  I did this because in the levelEditor class I know there will be an association occuring in the Draw function where I can place Size in. So if I wanted to change the size of a tile I could always change the value of Width or Height. To continue this I created a simple constructor called;

Tile(Texture2D texture, collisionType collision)

  Inside it I basically just assign the variables to eachother:

this.texture = texture;
this.collision = collision;

  Doing this completed the Tile class. Now all that's left to complete are four classes; camera, levelEditor, Animate, and Render! Can't wait to begin on the Animate class.

Monday, November 10, 2014

Creating a Game Engine: Class Diagram and Requirements List

  So to start this off, I am currently taking GSP 420 which is a course built on creating your own game engine. I have to say, before this class I've been eager in wanting to take this course because I've always wanted to make my own game engine. Into two weeks of the course me and my group have decided to create a game engine based around a platformer where we will be building it off of C# and XNA. The group I have is divided up into three cores; Main Framework Core, Graphics Core, as well as AI and Collision Core. Currently I am a part of the Graphics Core and I'm pretty comfortable with that only because I enjoy working with graphics! So to begin with our Game Engine we made sure to do some analysis planning through creating a class diagram and requirements list specific to our core. Being able to create a class diagram as well as a requirements list is a great way to get an idea of how the core's going to be structured as far as the system goes.

Graphics Core
Graphics Core
  As you can see with the above picture we have quite a few things going on with the graphics core and that's just only the graphics core. Since we want things to be almost pretty universal my thought behind this was to create a class which holds all sprites and this class was called spriteContainer. With this class other classes can just load a texture on screen just by invoking a specific variable such as player or enemy1 such as the levelEditor class. The levelEditor's purpose is actually what the name says, it edit's the levels properties as well as reads .txt files. In this class we can grab textures and set them to be a tile that blocks the players path, or a tile which determines the sprites exit point of a level. After setting up everything as pleased we can just draw all "tiles" based on the level index read and the file streamed. The cool thing with this class is the ability to read .txt files. So let's say we set a certain sprite to have a character of "P". Placing P in a .txt file will actually tell the compiler oh hay this is a platform. As you can see with the picture above there is an association going on with levelEditor and Tile. The purpose of tile is to take in an image from spriteContainer class where you can determine if the image is a platform, has a trigger, is visible or invisible. Now since our game engine is a platformer and we do want to be able to universally have the engine create an animation based off a sprite sheet we created an animation class called Animate, which associates with the spriteContainer class. So in Animate, it will take into account any sprite sheet, create a cell which shifts left or right, as well as determining if the animation loops or not. Now just so I don't get to into detail, it all comes down to the Rendering class. The whole purpose of this class is to Draw, which will draw all tiles based on the level in level editor, as well as render and update the screen coming from ScreenManager. Thus finishes the class diagram for our Graphics Core.
Requirements List
  Now it all comes down to the requirements List! I actually enjoy doing the requirements list a lot because it's great to use as a check off sheet such in a way when you begin testing you view your requirements list and see if the system follows all of the requirements. Usually when it comes to creating a requirements list, you want to get as thorough as possible because if there's a bug in your system and it has nothing to do with your requirements then that can go on the programmers fault. So when you look at the requirements list above, it doesn't look as thorough only because this is part of only the graphics core. The way me and my partner did it was pretty organize; labeling things by a requirement I.D as well as giving each description a status so we can use it as a check off sheet. When doing the requirements list, we did try to get as detail oriented as possible so in the instance when we test the engine we can make sure everything is running the way it should.

  Overall I'd have to say when it comes to creating some sort of system, whether its a software, program and or game engine...It's probably wise to do some planning before hand rather than diving into the production phase because then you might run into more errors versus if you had plan things out. A great way to actually plan things out can come from creating Class Diagrams, Use Cases, Requirement lists, as well as a Risk Assessment Table.

Tuesday, November 4, 2014

Getting started with FX Composer 2.5

  One of the things I enjoy a lot as a programmer is being able to handle things on the Graphics end. This can come from many things such as creating a user interface for games or handling 2D and 3D graphics and implementing them through a game engine or Direct X. Staring this new course excites me because we begin to approach more of the three dimensional aspects of Direct X such as messing with Shaders. One of the things we were first introduced to was something called FX Composer and I'd have to say the professor wasn't lying, it seriously looks like a combination of 3ds Max and a programming language combine together! FX Composer is basically a tool where developers on the graphics end can create or modify shaders through the use of creating an Effect file. The Effect file is then associated with a Direct3D program where a programmer can utilize that shader on a 3D model. With the use of DirectX Standard Annotations and Semantics (DXSAS) programmers are allowed to edit values of Annotations on a "host application" where they can actually modify the shader for their own use. So in other words we can utilize a shader on two different objects and have two different looks to it through tweaking the parameters of annotations.
FX Composer
  As you can see with the picture above, this is FX Composer and it really does look like a combination of 3DS max and C++! The middle window is the Editor or where all the programming lies where as the top left window is the material window. The top right window is the propeties window which gives you the properties of a material and the bottom right is the perspective window where you can see a mesh with the shader/material applied to it. So to start this all off, looking at the Phong effect file we can see quite a few things such as Lamp0Pos, Ambient, Bump, Ect. Under these you see annotations such as UIName, UIMin, UIMax and so on. These annotations have values which can be messed with through FX Composer or even through C++ which is great because that means you can dynamically change these values!

Effect Skeleton
  So the question you may ask yourself is how do you grab these annotations in C++? Well one way you can do this is through determining the annotations data type and then create a variable with that same data type and another variable which is a handler. So for instance, in this project we worked with the Gooch Bump Shader type. The shader has things where you can change it's warm color and cool color and it's data type dealt with color. So what I did was create four variables of type D3DXCOLOR and D3DXHANDLE and named it warmColor, coolColor, hWarmColor, hCoolColor. In the function where we load the effect file of the shader I grab the two handlers and had them call getParameterByName which took in the names of the semantics. Doing so basically said... okay we're going to assign these handlers to the semantics allowing you to edit their values as you please.

Renderer
  Thus leading me to the Renderer Function where I messed with the parameters setting warmColor to D3DXCOLOR(0.7f, 0.03f, 0.01f, 1.0f) and coolColor to D3DXCOLOR(0.01f, 0.05f, 0.25f, 1.0f). After setting the colors you have to set in the values which then you take into account the handler and the variable which you stored the color. With this I did
        m_pEffect->SetValue(hWarmColor, &warmColor, sizeof(D3DXCOLOR));
m_pEffect->SetValue(hCoolColor, &coolColor, sizeof(D3DXCOLOR));

  Which gave me the picture below:

Result
  For a first assignment I'd have to say this was quite fun and I look foward to what else FX Composer brings to the table!

Sunday, June 22, 2014

Implementing an Item Pickup through Unreal Engine with Kismet

  When some people hear about programming they may get scared away or even lost when talking about logic. Some people may even be intrigued to conversate just about logic itself. As days go on, programming is actually becoming a more easy thing to do and understand as we consider the amount of alternatives to actually programming on a programming language. For example, one of the things taught as a programmer of myself was understanding flowcharts. Flowcharts are just like pseudocode where you're basically writing out your logic without the syntax, the only difference is; flowcharts are more diagrams to help you out visually. Nowadays some programming languages like c++ on visual studio actually have things like UML diagrams which are similar to flowcharts in order to understand logic better, even game engines like Unreal have an alternative like this. With Unreal Engine 3, a programmer can create logic in two ways; scripting with Unreals Unreal script, or using Kismet which can be considered an alternative in writing down logic in a flowchart manner. Having used Unreal Engine 3 for quite some time and kismet honestly has helped me learn that you can approach logic with anything in many different kinds of alternatives. For example, recently when working on my midterm course project I had to create logic for my group game called Ruin where the player can be able to pick up Journals. So something very simple.

  Well when you think about it, how would we create logic for being able to pick up something on the floor in game. Well taking things step by step helps. What we want the player to be able to do is go up to the Journal, hit "U" and be able to pick it up and be placed in their inventory. What we DON'T want the player to be able to do is go any where in the level, press U and the journals picked up. Now that would be pretty bad. So considering that we know there should be an area where the player can go to in order to be able to pick up the journal and an area where they can't pick it up. Fortunately, thanks to Unreal Engine, they have a thing called Triggers. In a way, triggers can be seen as a boolean event. So if the trigger is touched, do this; else do this. The great thing about tiggers is that you can basically set up a parameter where when the player goes in, he's "touching" the trigger, and when the players outside the trigger he's "untouching" the trigger, so we can use this to our advantage.
 
  Seeing this now what we can do is have a cause of events taking place when the player enters or leaves the trigger. So considering how I don't want the player to be able to pick up the journal from the gecko, only in the triggers parameter, I actually created a bool variable by the name of "bCanPickUp" and set it to false upon level loaded. The point of this bool variable is to determine when the player can and cannot pickup the journal. Now for this one level we actually only had two journals so I made sure to create two more bool variables called "bIsBook1" and "bIsBook2" setting it to false upon level loaded. So you may be asking yourself how come I made three bools. Well picking up one journal can be easily done with one bool variable however, when we talk about more than one object being picked up with the same exact key we have to do more than one check to prevent the player from breaking the game.


   
  The two new bool variables I created bIsBook1 and bIsBook2 purpose are to check whether or not when the player hits U, are they picking up the first journal or second journal. After doing this I made sure to set up my triggers in the level right next to the journal. Upon clicking both triggers in the level I went into kismet hitting the right mouse button and going to New Event Using Trigger > Touch. Doing so placed two trigger events onto kismet. So after pre planning the logic I knew when the player touched one of the journals, than that player would be allowed to press U and pick up the journal. So upon the first trigger being touch I set bCanPickUp to true and bIsBook1 to true. So when the player touches trigger one, they are now allowed to press U and pickup something and what their picking up is Book1. Now the same thing I did for trigger one I did for trigger two.
 
  After doing this takes us to the journal checks now. The logic so far for the journal pickup is upon level loaded bCanPickUp, bIsBook1 and bIsBook2 are set to false and upon trigger touch either or may become true. Well although of this, nothing is happening. All I did was do a variable initialization and re assign the variables. To actually allow the player to pick the journals up we have to do another event which is a keypress event. To get to the key/ button press I went to New Event > Input > Key/ button press. With this event we can actually make it to when the player presses U he will pick up the journal. In the Key/ Button press node I added an input name by hitting the green plus sign and putting in U as the key to trigger the event. I also made sure to set the trigger count to zero to allow the player to be able to press the key as much as they want. After creating the new event I begun doing the checks. Considering there's more than one journal we have to do two checks. A check that determines if they are in the parameter to pick the journal up, and another check to determine what item they are picking up. Considering this, I made three compare bools found by going to New Condition >  Comparison > Compare Bool. With one of the compare bools I connected its input to the output UV of the Key/ Button press event. So when the player presses U we compare a bool. This bool will be bCanPickUp. So if bCanPickUp is true we then compare two more bools which is bIsBook1 and bIsBook2. With this I connected the input UV of the two last compare bools to the output of True of the first compare bool. On the bottom of the compare bools I attach the bool variable to the correct location to signify what we are testing.



 Doing this for journal one we have it when the player enters the triggered parameter we set bCanPickUp to true allowing them to press E and be able to pickup something. Well that comparison takes us to another check where it checks which journal they are picking up. So for journal one, if bIsBook1 is true, we destroy both that journal and that trigger to make it seem as if the player picked it up. Now after doing that feels good because the journal pick up is literally almost done......if you don't take into consideration that they're bugs the players can stumble upon. Well now when you think about it, the player can just keep pressed U over and over again destroy the mesh and trigger even when it's already destroyed. Now imagine if the journal pick had sound upon picking up. The sound would constantly play each time the player hit U. To prevent this what I did was in the compare bool upon bIsBook1 being true I set the variable bIsBook1 and bCanPickUp to False. So now when the player presses U nothing happens at all. With this first logic for the first journal I did with the second journal, the only difference is, when we go to the second comparison... when bIsBook2 == true we set bIsBook2 == false, bCanPickUp == false and we destroy that mesh and trigger. After doing this we got the pickup working but it doesn't seem really attractive. What I did after this was actually implement a flash movie I created in kismet so when the player enters the trigger,we play the movie that appears on the top right corner and when they leave the trigger, we stop playing it. The flash movie I made was of a open book popping in and out. Placing this into the logic was very easy.

  In order to place a flash movie like a journal pop up all I did was go to New Action > GFx UI > Open Gfx Movie. Upon touching the trigger we open the flash and upon leaving the trigger we close it. So what I did was connect the touch UV with the input In UV of  the open Gfx Movie node. In the Open Gfx Movie node properties I placed in my flash SWF by adding it in through the content browser by hitting the green arrow. After doing that I created a player variable and a object variable by going to New Variable > Player > player and New Variable > Object > Object. With these variables I connected them to to UV's Player owner and Movie Player. With the movie closing I went to New Action > Gfx UI > Close Gfx Movie. With this node I connected its input to the untouch Output of the trigger and also connected the movie player to the same movie player variable Open Gfx Movie has. Thus allowing when the player enters the trigger an swf plays and when they leave the trigger the swf closes.



  Believe it or not, even after doing this I didn't consider the pick up done. I actually went on and added sound to the pickup and a particle effect to make things seem more intriguing to see. Implementing sound with the pickup logic was pretty easy to do. All I did was in the second compare bool for both triggers; bIsBook1 and bIsBook2 I added a sound node by going to New Action > Sound > Play Sound and added my sound through the content browser by hitting the green arrow. After creating the sound nodes I connected the output of the comparison bool True to the input Play of the sound node. Now, just to make things safe I actually connected the finished ouput of the sound node to stop input of the sound just to make sure when the player pressed U again they won't hear a sound. Although I fix that upon setting the bools to false upon picking up the journal.


  After doing this I actually decided to add a particle effect at the location the player picks up either or journals. So when we destroy both the trigger and static mesh, we spawn an actor emitter of our particle. For my particle I created some clouds that spread apart on the floor. In order to get the particle to spawn and at the specific location I created an actor factory found in New Action > Actor > Actor Factory. In the properties of the actor factory node I dropped down the different types of actor factories we could choose from by hitting the blue downward arrow and selecting actor factory emitter. Still in the actor factory properties I drop down the Factory below the blue arrow giving us a place where we can place a particle system in. Grabbing my particle system from the content browser, I hit the green arrow to place it in the actor factory. Upon doing this I placed the Spawn Actor input UV and connected it to the true output UV of both compare Bools bIsBook1 and bIsBook2 for both triggers. So basically now upon picking up the journal we can now spawn the cloud particles but where is it? To get the system to be placed at the specific location of the book I connected the Spawn Point UV to the variable object of the static mesh, allowing the particle to play at the location of the mesh when destroyed.



  Thus actually completing the journal pickup for the game ruin



  Now in the instance where the player wanted to pick up an item and not destroy it, all they would have to do is attach the mesh to the actor by going to New Action > Actor > Attach to Actor and connecting the mesh to the Attach UV and player to the Target UV. For my group game called Ruin, I actually went this route for one of my artifacts where upon the player pressing U they pick it up and actually carry it. Now seeing how I still used the U key, expanded my checks for the journal pick up and Artifact pickup but still using the same logic.



  Overall when you think about it really, this journal pickup logic could've been done in many ways. It could've been done with integers, floats, or characters if we wanted to. I actually went with booleans because I prefer it more and I find it to make logic a lot much more simple. The cool thing about Unreal and Kismet is that whatever you can do in Kismet you can literally do in UnrealScript. So if I really wanted to, I could've scripted this logic myself instead of doing it through kismet. It all depends on what you prefer honestly, personally I would've done this through scripting if I had more time only because I prefer programming things out rather than using diagrams. However, like I said at the end of it all it's what you prefer.

Tuesday, June 17, 2014

Setting up an AnimTree for your Custom Playable Character

  Many of those that are familiar with Unreal Engine and any type of modeling program may be familiar with AnimSets as you import skeletal meshes into your levels. For those that aren't familiar, AnimSets is basically a set of animations a skeletal mesh can have. So for example, let's say we have a character model where we have an animation that the character is walking, upon exporting the skeletal mesh with the animation to the game engine Unreal, we get two things; the skeletal mesh, and an AnimSet of that animation. Now AnimSets can be very useful, for one you don't have to constantly re import an AnimSet for each animation you make in a modeling program. You could actually just import a new animation inside the AnimSet which makes scripting and the manipulations of AnimTrees much easier. Two, if you ever wanted to you could make animations in real time for your game using these AnimSets in Unreal's Matinee or even use AnimSet's for Cutscenes. Now with this being said, one of the main things AnimSets are good for are that you can implement them in a AnimTree. So you may be asking what is an AnimTree. Well for those that may not be familiar with the term, AnimTree's can be seen as a hierarchy tree that consists of different kinds of animations. So for some programmers out there...When Scripting your own custom playable character, having an AnimTree is pretty important. Without an AnimTree, you won't really see animations of your character going on in real time, such as the players moving animation. So if you were to script a playable character for a level or your game without an AnimTree, your player would definitely be able to move but animations won't be playing which is pretty unappealing.  Recently from one of the courses I've been taking, I had to create an AnimTree for one of the projects I was working on with my group called GirderJump. Basically you play as a construction worker who so happens to need to use the bathroom badly that you start jumping over obstacles such as girders to get to a porter potty. For this short game, I had to create an AnimTree for our playable character so that when the player actually moves the character, we can see animations playing.

 To start this off, I begun by actually creating a new AnimTree calling it "charaAnimTree" in my own package. Upon opening up the AnimTree your given basically everything blank, which is good if you like to start things new. So when I first begun making AnimTree's which was a course ago before me taking GSP340, I was lost. I honestly did not know where to begin and I remember being confused on why my skeletal mesh wasn't appearing in the previewer window. So to fix this was actually easy, all you have to do is click your AnimTree node and in the properties panel theres a preview mesh list. All you have to do is hit the green plus and insert your skeletal mesh in "preview Skel Mesh". Now upon doing this you'll get your skeletal mesh in but now you also want the AnimTree to recognize your AnimSet that contains all sorts of animations for the model. So just like what I did with the skeletal mesh, I placed in my AnimSet which was actually right beneath Preview Mesh List called Preview AnimSet List > Preview AnimSet.

  Upon me doing this I could now view my skeletal mesh and be able to play animations from that AnimSet. Now as a programmer and person that enjoys making 3D models, when making animations for skeletal mesh you have to think...What kind of mesh is this going to be? A character? And if so is he a playable character or AI? Thinking of things like these really do help out the thought process because then we get to narrow down what exactly needs to be down. For instance, this skeletal mesh was actually the main playable character for my group project called GirderJump. So the kinds of animations we would be needing is a character walking animation for front, back, right, and left, jumping animation, double jump animation if applicable, and down animation. For my game, things were much more simple considering it was a platformer side scroller game. So considering the camera angle, the only movements for the character walking animation I needed were front and back. And honestly, we could use the same animations for front and back. For my game, we actually had double jumping being applicable so there had to be some distinguishing from when the player first jumps to when the player double jumps. 
  Now after acquiring all animations (being done in 3ds Max) I was able to get starting with the AnimTree. As you can see above, what I started off with was called AnimNodeBlendByPhysics which connected the out UV from the AnimTree to the In UV of the new node. So to first explain things, any kind of model, whether its a static mesh or skeletal mesh can have physics apply to it. We can have walking physics, falling physics, interpolating which many game developers use when messing with matinee, and many more types. The AnimNodeBlendByPhysics which I got from right clicking anywhere in the grey area New Animation Node > BlendBy> AnimNodeBlendByPhysics basically has a set of physics that can be manipulated with your skeletal mesh. So for instance, in the PHYS_Walking UV we could put animations in for the character walking. So when actually playing the game, when the player were to move the physics would be set to walking. If the character jump, the character would have PHYS_Falling. So after having the AnimNodeBlendByPhysics I created a node called UTAnimBlendByIdle which I got from New Animation Node > BlendBy > UTAnimBlendByIdle, which is a node that blends with the state Idle and any type of moving state. So essentially we could connect a Idle state in the Idle UV which is when the player is staying still and add animations to the moving state, so when the player moves. Before going any further I made sure though to connect the PHYS_Walking UV with the input UTAnimBlendByIdle UV and then I created two things; an Animation Node sequence and a AnimNodeBlendDirection. The Animation Node sequence is where we will have our animations in. With our AnimSet in the AnimTree, we could easily call the name of the Animation we have inside the AnimSet in the Animation Node Sequence allowing the animation to work. The AnimNodeBlendDirection is pretty cool, with this node we can have movement in all directions being three hundred sixty degrees. So you'll have UV's for foward, backward, left and right. First, to get the Animation Node Sequence, I went to Animation Sequence > Animation Node Sequence. In the properties for this Node I name the Anim Seq Name to Idle and connected its input to the output to UTAnimBlendByIdle Idle output. So now we have our character in it's stationary state. Then I went to New Animation Node > Directional > AnimNodeBlendDirection and connected the input to the moving output of UTAnimBlendByIdle. After doing that I created two more Animation Node Sequence which are going to be placed in the foward and backward UV of the AnimNodeBlendDirection Node. Due to placing the AnimSet in our AnimTree we can literally just call our animation in the Anim Seq Name and the animation will go in. So for me, the animation for the character walking was charaWalk. Thus completing the character PHYS_Walking.


 
  Now for the project I was working on called GirderJump, we had jumping and double jumping being involved. So in total we were looking at three animations. So we know we will need three Anim Node Sequence. So what I did was create three Anim Node Sequence and name them the animations for jump, double jump and fall which were "charaJump", "charaDoubleJump", and "charaFall". After doing this I created something similar to UTAnimBlendByIdle but for PHYS_Falling which is called UTAnimBlendByFall and I got this from New Animation Node > BlendBy < UTAnimBlendByFall. With UTAnimBlendByFall we have a set of physics for falling, being jump, double jump, down, pre land, land ect. So we can take into account many animations for when the player is in the air. For my game, we only needed to take into account three. With the UTAnimBlendByFall input, I connected it to the output of PHYS_Falling and connected the charaJump node sequence to the UV of up, the charaDoubleJump node sequence to the UV of DoubleJump Up, and the charaFall node sequence to the UV's of  Down, PreLand, Double Jump Down, and Double Jump PreLand. Doing this completed the PHYS_Falling. So now the character can walk and fall.


  After doing this I had a few things left and the character was done. For one, I had to go to all Animation Node Sequence and in the properties panel I had to check off Playing and Looping and now we're down with the AnimTree.
  To actually implement the AnimTree in my game I had to place it into script along with the AnimSets. For this, it could be easily done in a few lines of four unreal classes; GirderJumpGame, GirderJumpPawn, GirderJumpFamilyInfo_Worker, and GirderJumpPlayerReplicationInfo. In my GirderJumpFamilyInfo_Worker I extended from UTFamilyInfo_Liandria_Male and in the DefaultPropeties I added the AnimSet that contains all animations of the character.


AnimSets(0)=AnimSet'GirderJumpModels.Walk'

In GiderJumpPlayerReplicationInfo I extended from UTPlayerReplicationInfo and in the DefaultProperties I added

CharClassInfo=class'GirderJumpGame.GirderJumpFamilyInfo_Worker'

which by doing that we now have all info from family worker, and we can now put replication info into the default properties of the game type.

Continuing this, I went into my GameType which was called GirderJump Game, and in the Default Properties, I added in

DefaultPawnClass=class'GirderJumpGame.GirderJumpPawn'
PlayerReplicationInfoClass=class'GirderJumpGame.GirderJumpPlayerReplicationInfo'

which takes into account now, my pawn class, and family info class.

Now we have mostly everything but we're missing one thing, which is the initialization for the character and the AnimTree. This, was simple. All I had to do was in the DefaultProperties of my pawn class;GiderJumpPawn. I added in these three lines:

  Begin Object Name=WPawnSkeletalMeshComponent
         AnimTreeTemplate=AnimTree'GirderJumpModels.charaAnimTree'
   End Object

What I did was create an object by the name of WPawnSkeletalMeshComponent and inside this object I initialize the AnimTree for the character. Thus doing this allows for my character animations to work in real time when playing.