Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 steviewondrs · Apr 08, 2013 at 02:06 PM · rotationbones

Bone movement by scripting using given angle as input.

I am currently working on a Unity project which uses a CyberGlove as input. It's bassically a glove with sensors which measures the angles between your fingers and joints. Now I want to simulate the movement in Unity by using a rigged hand so the hand on screen matches my real hand.

Could somebody provide me with a example on how to rotate bones with a given angle as input.

For example:

Angle: 45 degrees;

OnEvent() {

rotateJoint(angle, bone);

}

rotateJoint(angle, bone) {

// rotate bone 45 degrees

}

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
1
Best Answer

Answer by steviewondrs · Apr 09, 2013 at 08:28 PM

Allright, So I found the solution for rotating my skeleton joints with scripting First I mapped all the bones in public transforms, then I put them in an array, after which I can easily rotate them with EulerAngles.

     // mapping bones (drag and drop your prefered bones here)
     public Transform indexProximal;
     public Transform indexIntermediate;
     public Transform indexDistal;
     
     // array to store bones
     private Transform[] bones;
     
     // arrays to store the angles of the bones
     private Quaternion[] initialDirections; // for reset purposes
     private Quaternion[] boneDirections;
     private int ARRAYLENGTH = 3;
     
     void Start() {
         bones = new Transform[ARRAYLENGTH];
         initialDirections = new Quaternion[ARRAYLENGTH];
         boneDirections = new Quaternion[ARRAYLENGTH];
         
         // I map the bones into the array
         MapBones();
         // after which I store the initial directions
         GetInitialDirections();
     }
     
     // Map bones if they are available
     void MapBones() {
         if(indexProximal != null) { bones[0] = indexProximal;}
         if(indexIntermediate != null) { bones[1] = indexIntermediate;}
         if(indexDistal != null) { bones[2] = indexDistal;}
     }
     
     // get initial angles of bones in case the rig needs to be reset
     void GetInitialDirections() {
         for(int i = 0; ii < bones.Length ; i++) {
             initialDirections[i] = bones[i].localRotation;
             boneDirections[i]    = bones[i].localRotation;
         }
     }
     
     // update angles after every input
     void UpdateDirections() {
         for(int ii = 0; i < bones.Length; i++) {
             boneDirections[i] = bones[i].localRotation;
         }
     }
     
     // reset rig (this demonstrates the use of the 'initialDirections' array
     void ResetPositions() {
         for(int i = 0; i < bones.Length ; i++) {
             bones[i].localRotation = initialDirections[i];
             UpdateDirections();
         }
     }
     
     // Rotate joint to given angle
     void RotateJoint(int bone, float angle) {
         if(bones[bone] != null) {    
             Quaternion target = Quaternion.Euler(0, 0, angle); // define target angle, in this case a rotation around Z axis
             bones[bone].localRotation = target * boneDirections[bone]; // rotate bone to new position
             UpdateDirections(); // update the directions
         }
     }

Note: this script isn't finnished! I just put it here to show how I solved the problem, read it through and understand the code. (Oh and if you got any suggestions to improve, please reply)

Comment
Add comment · Show 2 · 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 theophilos01 · Jul 22, 2018 at 02:41 PM 0
Share

Hello sir. I am doing something similar but with the whole body (motion capture) I am using several I$$anonymous$$Us and get their rotations in Euler angles which I pass to unity. could we by any chance talk about how I should go about doing this? You seem to have worked this out an I am pretty new to unity so any help would be kindly appreciated.

avatar image hhemken · Jan 18, 2019 at 02:27 AM 0
Share

@steviewondrs and @theophilos01 I also want to drive a full body via scripting. Have you guys made more progress in that regard?

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

14 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Character Mouse Look on Spine 2 Answers

Simple lerp roation problem 1 Answer

rotation relative to world / starting position 1 Answer

How to tilt the gameobject based of Input.Acceleration? 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