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 josetgg · Feb 26, 2013 at 06:43 PM · 2d-platformerbonesrig

Moving bones of a model through code

Hi, Lets see if I can explain myself clearly: I have a rig arm with four bones, a root bone which is at the base, a tip bone at the top and two middle bones. What I want to do is to move the middle bones as if they were following the tip bone so if I move the tip bone diagonally to my up and right position of the screen my middle bones will follow in a normal looking way so that my arm looks as is extending diagonally, a and the game is a 2d sidescroller so I don't have to worry about z position. Right now I have the movement in the y axis working somewhat as I want with this code:

 //stores the bone that is going to be pulled by this one
 public GameObject previousBone;
     
 //when true this allows bone movement, this is for testing purposes
 public bool boneMoving = false;
     
 //stores the bonecontroller script from the other bone
 BoneController control;
 
 //diference in distances when the previous bone will start moving
 public float yDif = 1f;
 
 //percentage of the distance the previous bone will move
 public float yDiv = .8f;
 
 void Start ()
 {
   control=previousBone.transform.GetComponent<BoneController>();
 }
 
 void Update ()
     
 {
 
    if(boneMoving)
    {
     if(this.transform.position.y > previousBone.transform.position.y + yDif)
     {
        previousBone.transform.position = new Vector3(this.transform.position.x,this.transform.position.y * yDiv, this.transform.position.z);
     }
     else if(this.transform.position.y < previousBone.transform.position.y + yDif)
     {
        previousBone.transform.position = new Vector3(this.transform.position.x, this.transform.position.y * yDiv, this.transform.position.z);
     }
             
     if(control != null)
     {
        control.boneMoving = true;    
     }
             
     }
     else
     {
     if(control != null)
     {
        control.boneMoving = false;    
     }
             
     }
 }

This is only for vertical movement but I can't seem to figure out diagonal movement any suggestions are more than welcome thanks.

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 lauralexis · Nov 18, 2016 at 07:44 AM

I think that what you are looking for is inverse kinematics (IK). Unfortunately, I can not help you much with that, but you can search for some tutorials on IK on YouTube or here in the forums.

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

10 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

Related Questions

How can I make a certain bone rotate with the camera? 2 Answers

Remove bone from animator/rig 0 Answers

Can't move mesh limbs? 1 Answer

How to handle high heel footwear in Unity characters/rigs? 2 Answers

Muscles doesnt work in the avatar creation... 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