Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 yangyalinicole · Mar 26, 2017 at 09:20 AM · c#clonedragginggestures

how do i drag a clone object using gesture?

Hi everyone, our project is about using gesture. we are new to unity and only know c# , now we want to make the clone object able to drag.However, end up the original object able to drag but clone object cannot. I think we unable to achieve it because we don't know the name of the clone object and don't know how to call it. Can anyone give me an idea? Thanks a lot!

This is the script for clone obejct

void OnSelect() {

     furniture = (GameObject)Resources.Load(furnitureName, typeof(GameObject));
     BoxCollider bc = furniture.AddComponent<BoxCollider>() as BoxCollider;

     bc.center = new Vector3(0F, 0F, 0F);
     bc.size = new Vector3(0.01F, 0.01F, 0.01F);

     int i = 0;

     if(furnitureName == "Sofa")
     {
         //(+ forward, + up, + left)
         furniture.transform.position = new Vector3(-3.2F, 1.8F, 7.5F);
         furniture.transform.eulerAngles = new Vector3(1.349f, 178.41f, 1.213f);
         furniture.transform.localScale = new Vector3(0.2213F, 0.3970f, 0.1865f); 
     }

Instantiate(furniture);

 }

 private Vector3 GetHandPivotPosition()
 {
     throw new NotImplementedException();
 }

This is Script for dragging

public void StartDragging() { if (!IsDraggingEnabled) { return; }

         if (isDragging)
         {
             return;
         }

         // Add self as a modal input handler, to get all inputs during the manipulation
         InputManager.Instance.PushModalInputHandler(gameObject);

         isDragging = true;
         //GazeCursor.Instance.SetState(GazeCursor.State.Move);
         //GazeCursor.Instance.SetTargetObject(HostTransform);

         Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point;
         Vector3 handPosition;
         currentInputSource.TryGetPosition(currentInputSourceId, out handPosition);

         Vector3 pivotPosition = GetHandPivotPosition();
         handRefDistance = Vector3.Magnitude(handPosition - pivotPosition);
         objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition);

         Vector3 objForward = HostTransform.forward;

         // Store where the object was grabbed from
         objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition);

         Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition);
         Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition);

         objForward = mainCamera.transform.InverseTransformDirection(objForward);       // in camera space
         objDirection = mainCamera.transform.InverseTransformDirection(objDirection);   // in camera space
         handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space

         objRefForward = objForward;

         // Store the initial offset between the hand and the object, so that we can consider it when dragging
         gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection);
         draggingPosition = gazeHitPosition;
       //  GlobalVar.previpos = handPosition;
         StartedDragging.RaiseEvent();
     }



private void UpdateDragging() { Vector3 newHandPosition; currentInputSource.TryGetPosition(currentInputSourceId, out newHandPosition);

         Vector3 pivotPosition = GetHandPivotPosition();
       //  GlobalVar.previpos = pivotPosition;
         Vector3 newHandDirection = Vector3.Normalize(newHandPosition - pivotPosition);

         newHandDirection = mainCamera.transform.InverseTransformDirection(newHandDirection); // in camera space
         Vector3 targetDirection = Vector3.Normalize(gazeAngularOffset * newHandDirection);
         targetDirection = mainCamera.transform.TransformDirection(targetDirection); // back to world space

         float currenthandDistance = Vector3.Magnitude(newHandPosition - pivotPosition);

         float distanceRatio = currenthandDistance / handRefDistance;
         float distanceOffset = distanceRatio > 0 ? (distanceRatio - 1f) * DistanceScale : 0;
         float targetDistance = objRefDistance + distanceOffset;

         draggingPosition = pivotPosition + (targetDirection * targetDistance);
         GlobalVar.destPost = draggingPosition;
         if (IsOrientTowardsUser)
         {
             draggingRotation = Quaternion.LookRotation(HostTransform.position - pivotPosition);
         }
         else
         {
             Vector3 objForward = mainCamera.transform.TransformDirection(objRefForward); // in world space
             draggingRotation = Quaternion.LookRotation(objForward);
         }

         // Apply Final Position
         HostTransform.position = draggingPosition + mainCamera.transform.TransformDirection(objRefGrabPoint);
         HostTransform.rotation = draggingRotation;

         if (IsKeepUpright)
         {
             Quaternion upRotation = Quaternion.FromToRotation(HostTransform.up, Vector3.up);
             HostTransform.rotation = upRotation * HostTransform.rotation;
         }

       
     }
     //Assign the color from gazeablecolorpicker.cs to draw ^
 

     /// <summary>
     /// Stops dragging the object.
     /// </summary>
     public void StopDragging()
     {
         if (!isDragging)
         {
             return;
         }

         // Remove self as a modal input handler
         InputManager.Instance.PopModalInputHandler();
         if (firstTime)
         {
             GlobalVar.previpos = GlobalVar.position;
             firstTime = false;
         }
         isDragging = false;
         currentInputSource = null;

         //This will draw when it meet the start position and end position

         //GameObject myLine = new GameObject();
         //myLine.transform.position = GlobalVar.previpos;
         //myLine.AddComponent<LineRenderer>();
         //LineRenderer lr = myLine.GetComponent<LineRenderer>();
         //lr.material = new Material(Shader.Find("Particles/Additive"));
         //lr.SetColors(c1, c2);
         //lr.SetWidth(0.1f, 0.1f);
         //lr.SetPosition(0, GlobalVar.previpos);
         //lr.SetPosition(1, GlobalVar.destPost);
         //GlobalVar.previpos = GlobalVar.destPost;

         StoppedDragging.RaiseEvent();

     }
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

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to detect if an object is being moved back and forth by the user? 0 Answers

Instantiate creating infinite clones 0 Answers

Problems with GameObjects localScale 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