myo + oculus rift tutorial

18
Myo + Oculus Rift Tutorial Chris Zaharia @chrisjz

Upload: chris-zaharia

Post on 21-Apr-2017

4.034 views

Category:

Devices & Hardware


0 download

TRANSCRIPT

Page 1: Myo + Oculus Rift Tutorial

Myo + Oculus Rift Tutorial

Chris Zaharia @chrisjz

Page 2: Myo + Oculus Rift Tutorial

Content

• Develop simple mage game in virtual reality• Shoot magic projectiles using hand gestures• Aim by rotating arm• Defeat hoard of spiders

Download the game at chrisjz.github.io/myogic

Page 3: Myo + Oculus Rift Tutorial

Myo Dev Kit

• EMG sensors for gesture detection• Gyroscope• Accelerometer• Magnetometer• Bluetooth• Full day battery charge

Page 4: Myo + Oculus Rift Tutorial

Myo Dev Kit vs Leap MotionMDK Leap Motion

• Fixed gestures (six)• 2D arm tracking• Wireless

• Finger tracking• 3D hand tracking• HMD Mountable

Page 5: Myo + Oculus Rift Tutorial

Wireless VR

Page 6: Myo + Oculus Rift Tutorial

Requirements

• IDE• Unity Pro 4.6+

• Myo• Myo Connect 0.7.0+ (Win/Mac)• SDK Beta 7+ (Win/Mac)

• Rift DK2• Unity 4 Integration 0.4.4+

Page 7: Myo + Oculus Rift Tutorial

Scope

• Integrate Oculus VR player into game scene• Attach Myo controller to arm-hand model• Map several magic attacks to hand gestures

Page 8: Myo + Oculus Rift Tutorial

Getting Started

• Download the source code for Myogic at github.com/chrisjz/myogic

• Create a folder in the Assets directory called TutorialScenes.

• Copy the scene and corresponding folder from Palace of Orinthalian > [Scenes] to TutorialScenes.

• Open the copied scene. Download the game at chrisjz.github.io/myogic

Page 9: Myo + Oculus Rift Tutorial

Create OVR Player

• Add the OVRPlayerController prefab into the root [Character] gameobject.

• Disable the existing First Person Controller gameobject.

Page 10: Myo + Oculus Rift Tutorial

Hand Model Positioning

• In the gameobject OVRCameraRig create the gameobjects Hands > Right.

• Place the prefab GlowRobotFullRightHand in Right and position it on the right of the player’s view.

• Set scale of the right hand to 5x5x5.

Page 11: Myo + Oculus Rift Tutorial

Integrate Myo Controls with Hand

• Place the Hub – 1 Myo prefab in the root of the hierarchy.

• Attach the script JointOrientation to the OVRCameraRig > Hands > Right gameobject.

• Drag the Myo gameobject into the Myo variable in the JointOrientation script.

Bug fix: Set Rotation Amount to 0 in OVRPlayerController as JointOrientation has an existing bug where the arm rotates

incorrectly when the player rotates.

Page 12: Myo + Oculus Rift Tutorial

Setup Magic Powers

• Create a Plane object under Right gameobject and position in front of the hand model’s index finger.

• Name the plane object MagicLauncher and disable its Mesh Collider and Mesh Renderer and ensure its X axis faces forward from finger.

• Attach a new C# script called MagicController on Right gameobject.

Page 13: Myo + Oculus Rift Tutorial

MagicController.cs (1)using UnityEngine;using System.Collections;

using Pose = Thalmic.Myo.Pose;

public class MagicController : MonoBehaviour {// Myo game object to connect with.// This object must have a ThalmicMyo script attached.public GameObject myo = null;

// Point from where magic projectiles will launch from the hand.// This object must be a plane placed either in front of the palm or at the tip of the hand's fingers.public GameObject handMagicLauncher;

public GameObject fistProjectile;public GameObject waveInProjectile;public GameObject waveOutProjectile;

// Speed of projectilepublic float fistSpeed = 1000;public float waveInSpeed = 1000;public float waveOutSpeed = 1000;

// Cooldown until next projectile can be launchedpublic float projectileCooldown = 1;

protected ThalmicMyo myoController = null;

private float projectileTimer = 0;

Page 14: Myo + Oculus Rift Tutorial

MagicController.cs (2)void Start () {myoController = myo.GetComponent<ThalmicMyo> ();}

void Update () {if (!myo && !myoController)return;

if (projectileTimer > 0) {projectileTimer -= Time.deltaTime;return;} else {projectileTimer = projectileCooldown;}

switch (myoController.pose) {case Pose.Fist:Attack (fistProjectile, fistSpeed);break;case Pose.WaveIn:Attack (waveInProjectile, waveInSpeed);break;case Pose.WaveOut:Attack (waveOutProjectile, waveOutSpeed);break;}}

Page 15: Myo + Oculus Rift Tutorial

MagicController.cs (3)protected void Attack(GameObject projectilePrefab, float speed) {

GameObject projectile;

projectile = (GameObject) Instantiate (projectilePrefab.gameObject, handMagicLauncher.transform.position, Quaternion.identity);

projectile.rigidbody.AddForce (handMagicLauncher.gameObject.transform.forward * speed);}

}

Page 16: Myo + Oculus Rift Tutorial

Set Magic Public Variables

• In the MagicController script, set the following for the public variables:– Myo – Drop in the scene’s Myo object.– HandMagicLauncher – Drop the MagicLauncher

object under the Right gameobject.– “—” Projectiles – Set as any of the projectile

prefabs in Projectiles > Prefabs.• Optionally you can also change the speed of

each projectile and the cooldown period.

Page 17: Myo + Oculus Rift Tutorial

Extras

• Add enemy spiders to the scene from Enemies > Spider > Prefabs and play around with its health, speed, FOV, size etc.

• Add new magic attacks and change their attributes.

• Add player health and damage to make the game more challenging.

Page 18: Myo + Oculus Rift Tutorial

Good Luck!