My First “Real” Magic Leap Project: Part 5

John Tucker
Coinmonks
3 min readAug 10, 2018

--

We implement the Aim and Action modes; refactoring statement along the way.

This article is part of a multi-part series starting with My First “Real” Magic Leap Project: Part 1.

The completed application for this article is available for download from the part5 branch of the bounce repository.

Re-Re-Refactor

In the previous article, we avoided using global state for rapidly changing values, e.g., the position / scale of the MeshingZone, by creating a reference in MLSpatialMapper2 to MeshingZone.

As I went to use this pattern for a second time, it was already feeling like I was going to end up with spagetti code. So instead, I pivoted to using static properties on a class Global to share global state (a simplified global state). This is for global state that does not need the observer pattern, i.e., active updates are not required. I continue to use the Redux-like pattern for global state that needs active updates, e.g, Mode.

Assets / Store / Global.cs

Then we use the simplified global state:

Assets / Table / MLSpatialMapper2.cs

3D Modeling Tool (Blender)

When I went to build the game object to aim the ball, I decided that I needed a more complex shape than was available in Unity; this is when I learned about 3D Tools and in particular Blender.

While Blender has its own steep learning curve, I fairy quickly built a model that I imported into Unity to serve as the game object for aiming.

note: While the color is correct; I did not get the smoothness to match the existing game objects; could have likely spent some more time and got this correct.

Aim and Action

In the Aim mode, the user uses the touch pad on the controller (left and right) to rotate the Aim game object to indicate the direction to later launch the ball.

Having refactored touchX into the simplified global state, it was fairly easy to implement controlling the orientation of the Aim game object. At the same time, we use the observable pattern to trigger updates on changes in Mode.

Assets / Table / Aim.cs

Having aimed the ball, the user makes the Ok hand pose with their right hand to launch the ball in the selected direction.

Observations:

  • As expected, the ball bounces off the first mesh mapped from the blocks
  • But.. The ball passes through the second mesh mapped from the blocks; it is my assumption that this is because we did not “walk around the table” to mesh all the faces of the block. Just like a basic Unity Plane game object, the mesh objects do not collide on their back-faces’.

Next Steps

We wrap up the series focusing on building the user interface (UI) elements (score, etc.) in the next article: My First “Real” Magic Leap Project: Part 6.

--

--

John Tucker
Coinmonks

Broad infrastructure, development, and soft-skill background