• 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 Giantbean · Dec 17, 2021 at 01:24 AM · rotationnetworkingchild object

Check when rotation of child object has stopped?

I am trying to find when the rotation of a child joint on a hand rig has stopped moving. I need to know when it has stopped so I can hide the hand. (leap motion controller w/ multi player issue)

The item is kinematic so I cant check velocity

 //All the multiplayer stuff works I just cant hide the hand
 netLeftPalm.transform.position = localLeftPalm.transform.position;
  netLeftPalm.transform.rotation = localLeftPalm.transform.rotation;
 
 //Fails as kinematic rigidbodys are always zero and gravity is always falling
   Rigidbody sleeper = netLeftPalm.GetComponent<Rigidbody>();
    if (sleeper.velocity.sqrMagnitude < stopThreshold && sleeper.angularVelocity.sqrMagnitude < stopThreshold)
   {
      //Works on mesh renderer or skinned mesh
      netLeftHand.transform.localScale = Vector3.zero;
      }
       else
       {
       netLeftHand.transform.localScale = Vector3.one;
       } ...

using a kinematic rigid body I can check if its sleeping but its not good:

 if (netLeftPalm.GetComponent<Rigidbody>().IsSleeping())
 {
  //by scaling the root object when the leap motion losses tracking the hands disappear rather then being left floating disembodied.
  // This however seems to cause issues with the rig stretching and bouncing before it disappears.
  //If done on a single object however this works fine just not on a rigged object.
     netLeftHand.transform.localScale = new Vector3(0, 0, 0);
     }
     else
     {
      //Note: also tried to force uniform scaling with the same result, still its the best so far.
      netLeftHand.transform.localScale = Vector3.one;
      } ...

Trying to disable the object or turn off its render has also failed over the network but the joints positions work fine when using if(isLocal)...

 //Simply setting the root hand to active leaves it floating for some reason
    netLeftHand.SetActive(false);
 
  //same thing when disabling the renderer so this is not syncing over the network
      netLeftHand.GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;

I tried using .haschanged

    //No dice. Seems like it should work as the rotation changes while the hand is in frame and stops when its not.
     if (netLeftPalm.transform.hasChanged)
     {
         netLeftHand.transform.localScale = Vector3.zero;
         transform.hasChanged = false;
     }
     else
     {
         netLeftHand.transform.localScale = Vector3.one;
         transform.hasChanged = true;
     }

I tried some rotation script but had issues.

 //speaking of dice lets try tracking the roll... Doesn't work as its slow causing lag and reads the wrong objects rotation.
 currentRotation = netLeftPalm.transform.rotation;
 if (Mathf.Abs(Quaternion.Angle(rotationStored, netLeftPalm.transform.rotation)) < maxErrorAllowedPerFrame || currentRotation == rotationStored)
  {
      inRange = true;
   }
    else
   {
     inRange = false;
    }
 
    rotationStored = netLeftPalm.transform.rotation;
     if (inRange)
     {
       netLeftHand.transform.localScale = Vector3.zero;
      }
        else
      {
        netLeftHand.transform.localScale = Vector3.one;
       } ...

Any ideas on how I can get the rotation of the child joint when the transform position is not changing and the rotation is not effecting the velocity?

Comment
Add comment · Show 3
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 Giantbean · Dec 17, 2021 at 04:47 PM 0
Share
 if (Mathf.Abs(oldEulerAngles.x - netLeftHand.transform.rotation.eulerAngles.x)<stopThreshold)
                 {
                     //NO ROTATION
                     netLeftHand.transform.localScale = Vector3.zero;
                 }
                 else
                 {
                     Mathf.Abs(oldEulerAngles.x - netLeftHand.transform.rotation.eulerAngles.x);
                     //ROTATION
                     netLeftHand.transform.localScale = Vector3.one;
                 }

Fails to ever scale to one and if you remove the Math.Abs and .x it flickers between one and zero making the hand stretch again like it does with the rigidbody.isSleeping test. My best guess is that its seeing rotation on the parent as well as the rotation of the specified game object.


Edit: Testing with the MathF.Abs it stretches the hand in and out with a threshold of 0.000001f


2nd Edit: I just realized I was using the hand rotation in this test and when using the palm rotation it works better with a stop threshold of .001 Its almost right but still gives me the stretchy hand every now and then.

avatar image Giantbean · Dec 17, 2021 at 05:20 PM 0
Share

This seemed to work in a local test but does not work when networked

 if (Mathf.Abs(oldRightEulerAngles.x - netRightPalm.transform.rotation.eulerAngles.x) < stopThreshold)
 {
     //NO ROTATION
     netLeftHand.GetComponentInChildren<SkinnedMeshRenderer>().enabled = false;
 }
 else
 {
     oldRightEulerAngles = netRightPalm.transform.rotation.eulerAngles;
     //ROTATION
     netLeftHand.GetComponentInChildren<SkinnedMeshRenderer>().enabled = true;
 }


avatar image Giantbean · Dec 17, 2021 at 10:22 PM 0
Share

Using the Mathf.Abs soutuion above I and calling CmdLeftHandDisable(); or CmdLeftHandEnable(); with:

 [Command]
     void CmdLeftHandEnable()
     {
         if (isClient) netLeftHand.gameObject.SetActive(true);
         else RpcLeftHandEnable();
     }
 
     [ClientRpc]
     void RpcLeftHandEnable()
     {
         netLeftHand.gameObject.SetActive(true);
     }
 
     [Command]
     void CmdLeftHandDisable()
     {
         if (isClient && isLocalPlayer) netLeftHand.gameObject.SetActive(false);
         else RpcLeftHandDisable();
     }
 
     [ClientRpc]
     void RpcLeftHandDisable()
     {
         netLeftHand.gameObject.SetActive(false);
         Debug.Log("Left Hand Disable");
     }

Works perfectly for the client but the Host gets really screwed up. I think I will need to open a new networking question.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

260 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 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

Executing command in a child GameObject in a multiplayer Game 2 Answers

rotate child relative to parent,rotating child object in relation to parent 2 Answers

parent and child 1 Answer

Network Rotation not sync 2 Answers

Child OWN Rotation 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