Showing posts with label LeapMotion. Show all posts
Showing posts with label LeapMotion. Show all posts

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!