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 /
  • Help Room /
avatar image
0
Question by ashomran · Oct 28, 2018 at 12:36 PM · runtimekinectsnapsnapping

Snapping using kinect v2 sdk

Hello guys, i got some kind of question maybe it is a lil complex. i am using kinect v2 sdk and drag and drop scripts from it. i tries to add a snapping script using colliders enter and mouse release method. my script works fine with mouse dap and drop but when it comes to control via kinect it looses snapping effect. so my question is how to get it configured to work with kinect libraries?

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

Answer by ashomran · Oct 28, 2018 at 12:40 PM

this is my snapping script.

 using UnityEngine;
 using System.Collections;
 
 public class Snap : MonoBehaviour {
 
     public  string partnerTag;
     public  float closeVPDist = 0.05f;
     public float farVPDist = 1;
     public  float moveSpeed = 40.0f;
     public  float rotateSpeed = 90.0f;
 
     private Vector3 screenPoint;
     private Vector3 offset;
     private bool isSnaped;
     Color color = new Color(1, 0, 0);
 
     float dist = Mathf.Infinity;
     Color normalColor;
     GameObject partnerGO;
     // Use this for initialization
     void Start () {
         normalColor = GetComponent<Renderer>().material.color;
         partnerGO = GameObject.FindGameObjectWithTag(partnerTag);
     }
 
     void OnMouseDown()
     {
         screenPoint = Camera.main.WorldToScreenPoint(transform.position);
         offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
         Cursor.visible = false;
     }
 
     void OnMouseDrag()
     {
         //transform.SetParent(null);
         Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
         Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
         transform.position = curPosition;
         Vector3 partnerPos = Camera.main.WorldToViewportPoint(partnerGO.transform.position);
         Vector3 myPos = Camera.main.WorldToViewportPoint(transform.position);
         dist = Vector2.Distance(partnerPos, myPos);
         GetComponent<Renderer>().material.color = (dist < closeVPDist) ? color : normalColor;
     }
 
     void OnMouseUp()
     {
         Cursor.visible = true;
         if (dist < closeVPDist)
         {
             transform.SetParent(partnerGO.transform);
             StartCoroutine(InstallPart());
             isSnaped = true;
         }
         if( dist > farVPDist)
         {
             //  transform.SetParent(null);
         }
     }
 
     IEnumerator InstallPart()
     {
         while (transform.localPosition != Vector3.right || transform.localRotation != Quaternion.identity)
         {
             transform.localPosition = Vector3.MoveTowards(transform.localPosition, Vector3.right, Time.deltaTime * moveSpeed);
             transform.localRotation = Quaternion.RotateTowards(transform.localRotation, Quaternion.identity, Time.deltaTime * rotateSpeed);
             yield return new WaitForEndOfFrame();
         }
     }
 }


it works fine with mouse controling.

Comment
Add comment · Show 1 · 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
avatar image ashomran · Oct 28, 2018 at 02:28 PM 0
Share

i need to change (On$$anonymous$$ouseUp, On$$anonymous$$ouseDown, On$$anonymous$$ouseDrag) to be like kinect call it HandRelease,Grip and none

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

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving an object a fixed amount on its local axis 1 Answer

How would I Consistantly 'Snap' a UI Element to the Edge of a Camera? 1 Answer

snap object to another object 2 Answers

Swipe to rotate an object and when it reach 30° snap it to 90° 0 Answers

Need help with snapping Prefab assets to grid in game 2 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