Magnetic Pinch with Leap Motion Orion
And why it is nearly impossible (yet) to throw things in VR like you do in real life.
With the original Leap Motion SDK came the Magnetic Pinch, a script that allowed to grap an object closest to the hand so you could throw it around. You can still get it on Github. Yet, with the new Leap Motion Orion (it’s a pretty good option for VR hand tracking. Go check it out!) the script is no longer working. The closest you will find in the latest release is a Pinch Detector, however, it does not allow to select single objects, nor throwing them around.
For anyone new to VR, Unity and the Leap Motion, it can be quite tricky to get virtual hands to the point where they can pick up objects and throw them. I will present a solution here (go find the code at the bottom of this page). I am not a professional coder, so the code may lack performance and beauty, yet it should be easy to understand. It takes snippets from the original Magnetic Pinch (thanks Leap Motion!) and may just need a tiny bit of additional polishing (English is not my native tongue but I think it would be right to say “… a bit of polish” here. However, that sounds strange and you wouldn’t have to speak polish to understand it…). Oh, and if you are really really new to VR and Unity, have a look at my very first story:
What does it mean to throw objects in VR
See what I mean when I talk about throwing things around:
Looks weird? I don’t really grab the sphere here, I know. I intend to grab it, but then it just wooshes out my hand and attaches to a point somewhere at the back of my middle finger. Altough this looks not correct, it is intentional. Putting the sphere inside your hand makes it much harder to keep control of throwing speed, distance and trajectory. Try it yourself (adjust the code so that “IsKinematic” stays true just until you release the object). Having the sphere attached outside your hand lets you better control its behaviour. If you try, keep calm! Don’t be too quick! Slooowly! And always keep the object in the center of your visual field. Voilà, you are a 2-year old again, learning how to throw a ball.
Throwing objetcs in VR just doesn’t feel like it does in real life, and you need some extra training which makes it much less intuitive. I think there is a couple of reasons for that:
#1, you miss out on haptic feedback (be careful of the wall/table/chair infront of you).
#2, usually, when you throw things in real life, you move your hand to gain momentum (in VR you can do this inside your visual field, without a problem), then you move your hand quickly towads the target and release the object. Here, at least, you usually loose visual track of your hand for a few milliseconds. This is not a problem in real life because you sense other things that make your shot complete. For the Leap Motion, however, any time your hand leaves the tracking area, the cameras loose track, too. In VR, you will soon recognize that you always have to keep your throwing motion in focus. Always! And this just doesn’t feel very natural…
#3: It is quite difficult for the object to know your intentions. Usually, the object should travel the way your hand moves, once you release. Therefore you would need code that predicts your hand movements. As I said earlier, I am not a professional coder, so instead of trying to predicting the future, the script presented here lets the object always lack behind the pinch position; this is to let it gain momentum. However, it requires some learning if you really want to hit a target.
Let’s get to the script
As you can see, throwing objects in VR comes with quite some limitations that have a major impact on the experience. Whatsoever, if you want to try it yourself, go ahead. In Unity, add the script below to your right or left hand and have fun doing some toddler-trowing. The magnetic pinch is very easy to implement and doesn’t do your VR-happiness any harm. However, the throwing aspect does, i’m afraid…
Add a Rigidbody to any object that you want to interact with and enable “Is Kinematic” if you want your hand to reach into the object instead of pushing it away, once you grab for it. Also, don’t forget to add the Magic Leap Orion’s PinchDetector to your virtual hand.
I wrote the script during the process of a thesis project. I’ll soon release the results of my evaluation and post some design principles for VR interaction models. Hope this snipped here helps you doing some great interactive VR work and I hope you’ll like what will come in the future!