Tutorial: The Collisions DemoΒΆ

The Collisions Demo example illustrates how to add hands to a level that can interact with simple objects through collisions. The Unreal Engine project containing this example is available in our Example Gallery at: https://developer.leapmotion.com/gallery/unreal-4-7-demo-pack.

In this tutorial, we will recreate the CollisionsDemo level, which places a Leap Motion Controller Actor in the scene along with a pile of blocks to knock around.

You can examine the already-built level in the Leap Examples project to see what we will be building. Open the Leap Examples project and double-click on Maps/CollisionsDemo. You should see a stack of blocks on the default Unreal floor. Go ahead and give them a whack:


The collisions demo in action.

Now, let’s get started by creating a new level and a custom Leap Motion Controller Actor Blueprint. You can refer back to the CustomControllerDemo map for reference.

  1. File > New Level

  2. Choose the Default template, which has a floor and skybox.

  3. Add a Leap Motion Controller Actor just in front of the Player Start marker.

    1. Type “Leap” in the Mode panel to locate the controller actor class.
    2. Drag the Leap Motion Controller Actor into the level.
  4. Add cubes to the map:

    1. Find the Static Mesh cube object in the Engine Content folders (really any of the geometric static mesh objects will do).

    2. Place the cube just in front of the Leap Motion Controller Actor.

    3. Set the cube properties:

      • Scale = (.2, .2, .2)
      • Moveable = True
      • Simulate Physics = True
    4. Copy the placed cube and paste more instances into the level.

And that’s it!

The hands are oriented to the position and rotation of the Leap Motion Controller Actor object. Imagine that the physical Leap Motion device is placed in your 3D world. Then your physical hands have the same relationship to the device as the 3D hands have to the virtual Leap Motion Controller Actor.

At the code level, the Leap Motion Controller Actor maintains an internal connection to the Leap Motion service. When a hand is detected, it creates a new LeapMotionHandActor object to represent it. The hand actor, in turn, creates LeapMotionBoneActor objects to represent each part of the hand (including the arm, palm, and three segments per finger). Physical positions, rotations and sizes are all translated into the Unreal coordinate system. Likewise, collisions are handled by the default Unreal Engine behavior.