/Cube-Fight

Multiplayer augmented reality game using Magic Leap powered by PubNub.

Primary LanguageC#

Cube Fight

Multiplayer augmented reality game powered by PubNub.

Magic Leap Multiplayer Demo

Augmented reality is a fresh new layer for gaming that promises new experiences for users and more revenue for game studios. However, AR brings new challenges to traditional game design when you start to build multi-user games and need to sync content between them. Even in single player games where there's no content to sync, there's a significant demand from users to add social experiences like chat and leaderboards.

The objective of Cube Fight is to take cubes from other players by using the Magic Leap Eye Gaze feature to select a cube and the trigger on the controller to take it. PubNub will handle transmission of messages regarding the ownership state of each cube.

Learn more about how to build your own multiplayer AR game with Magic Leap and PubNub from the tutorial.

PubNub Blog

Why PubNub and Magic Leap?

This is Part three of my Magic Leap series. Check out the other projects/posts Getting Started with Magic Leap and PubNub and Controlling Internet-connected Devices with Magic Leap Hand Gestures.

Developers have been building multiplayer games and other multi-user experiences with PubNub for years, and PubNub definitely sees AR as next on the horizon. PubNub is a natural fit in the AR world and their technology can power the realtime interaction between AR headsets or physical objects in the same location, or even across the Earth.

For instance, when a Magic Leap user throws a ball in the virtual world, that motion is synchronized in realtime across every other connected user. Or if a user uses a hand gesture to turn on a light, PubNub is sending the message to that light to turn on. Multi-user experiences, or the relationship between the AR headset and the physical world around us, is where PubNub is required and excels.

How it Works

This game uses Magic Leap Eye Gaze to select game objects (the cubes) and the trigger on the controller to take them. Additionally, there's an eye position indicator to aid the user in knowing where the device thinks they are looking.

There are three states/colors each cube can be in:

  • Not Focused (red) - The user is not looking directly at the cube, has not taken the cube, and another player owns the cube.

Not Focused Cube Fight Cube

  • Focused (dark red) - The user has looked at, but not taken the cube and another player owns the cube. Notice the eye position indicator is on the cube (the blue sphere).

Focused Cube Fight Cube

  • Owned (blue) - The user has looked at and took the cube by pulling the trigger.

Owned Cube Fight Cube

Each cube has the script "EyeSelection" as a component. This script handles eye tracking and controller events. When the player looks directly at a cube and pulls the trigger a message is published to PubNub to inform other players of the ownership change. When the players receive a message the cube color is updated to reflect the current state of the cube.

How to Build

The tutorial Create a Multiplayer Augmented Reality Game with Magic Leap and Unity details how to build and run this project in full.

What's Next?

The augmented world is your oyster with Magic Leap + PubNub. Here are a few ideas to get you started:

Have suggestions or questions about the content of this post? Reach out at devrel@pubnub.com.

This is Part three of my Magic Leap series. Check out the other projects/posts Getting Started with Magic Leap and PubNub and Controlling Internet-connected Devices with Magic Leap Hand Gestures.