Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shala28 · Jan 27, 2016 at 03:17 PM · unity5

How to use leap motion in unity, using your hands to control a different game object?

I am a fairly new user to Unity, as part of my studies. Currently, in the scene I have a stick that I want to move using my hands being tracked by the leap motion device. I found a script online to help me do this, which I basically link to the Hand Controller Prefab that comes with Leap motion integration files for unity and attached this to the stick. The stick does move at the moment but the orientation seems to be off (horizontal and vertical have switched). e.g. if my hand is at a vertical angle the stick is horizontal. Also the movement does not seem to be stead. I couldn't find any other answers that could give me an idea as to why it isn't working, as about a month ago the orientation was perfect. When I came back to it, I changed nothing but it wasn't working. I'm trying to get this all to work so you can see it in the Oculus Rift, which the HMD view is working just fine, the leap motion is being temperamental.

Wondering if anyone has any suggestions to how to fix it or a different way to get my hand movements to be linked to a game object so the stick moves as if it is my hand? Hopefully this makes sense.

The script I'm using is shown below:

using UnityEngine; using System.Collections; using Leap;

public class MatchHand : MonoBehaviour {

 //Assume a reference to the scene HandController object
 public HandController handCtrl;

 void Update()
 {
     Frame frame = handCtrl.GetFrame();
     Hand hand = frame.Hands.Frontmost;
     if (hand.IsValid)
     {
         transform.position =
           handCtrl.transform.TransformPoint(hand.PalmPosition.ToUnityScaled());
         transform.rotation =
           handCtrl.transform.rotation * hand.Basis.Rotation(false);
     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tain_M · Jan 28, 2016 at 12:35 AM

The steadiness issues are probably because you are using Update() without compensating for the variable frame rates. https://unity3d.com/learn/tutorials/modules/beginner/scripting/update-and-fixedupdate

I'd try using Time.deltaTime as a multiplier for your position/rotation, which causes changes to vary based on the time between frames, which forces the motion to be evenly spaced. As an alternative, you can use FixedUpdate(), which updates every .02 seconds, giving a reliably spaced experience. However, this is usually used for Physics not for User Input.

If your stick is vertical when your hand is horizontal, and visa-versa, then your issue probably has to do with which axis your rotation is occurring on. You should be able to either add a multiple of 90 degree to correct the offset, or manually change which axis your HandController object or Hands object is interacting with.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Android audio lag issue, any way to reduce the lag? 1 Answer

Error while Running on Ios device with 64 bit processor (ipad air, iphone 6) 0 Answers

Problem After Building Game In Unity 5 1 Answer

Manual Activation for Unity5 when no internet 1 Answer

No realtime shadows in webplayer build? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges