Post on 13-Jul-2015
transcript
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
Myo Dev Kit
• EMG sensors for gesture detection
• Gyroscope
• Accelerometer
• Magnetometer
• Bluetooth
• Full day battery charge
Myo Dev Kit vs Leap Motion
MDK Leap Motion
• Fixed gestures (six)• 2D arm tracking• Wireless
• Finger tracking• 3D hand tracking• HMD Mountable
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+
Scope
• Integrate Oculus VR player into game scene
• Attach Myo controller to arm-hand model
• Map several magic attacks to hand gestures
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
Create OVR Player
• Add the OVRPlayerController prefab into the root [Character] gameobject.
• Disable the existing First Person Controllergameobject.
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.
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 Myovariable in the JointOrientation script.
Bug fix: Set Rotation Amount to 0 in OVRPlayerController as JointOrientationhas an existing bug where the arm rotates
incorrectly when the player rotates.
Setup Magic Powers
• Create a Plane object under Right gameobjectand position in front of the hand model’s index finger.
• Name the plane object MagicLauncher and disable its Mesh Collider and Mesh Rendererand ensure its X axis faces forward from finger.
• Attach a new C# script called MagicControlleron Right gameobject.
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;
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;
}}
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);
}
}
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 MagicLauncherobject 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.
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.