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
1
Question by inco · Oct 11, 2012 at 12:06 AM · rotationhierarchybonesnestedbending

Smoothly bend around a point - rotation problem.

Hello there,
Last time my question went unanswered, but I managed to 'stitch' objects to follow each other (having the first bone in chain follow the last bone of the object in front) in a train-like configuration, however now I'm faced with more serious problem which I've been trying to solve for the past week to no avail.

Since all animation has to be done by code now smooth bending around a corner (when the pipe takes a turn) became quite challenging. Basically, my idea is to create an arch which I'll use as a guide for the bones in each segment and then animate through it. For that purpose I'm using an imaginary point O around which I want to bend the pipe, and the arch is defined by a radius r (in this case the distance between the center of the pipe and the point O, on the axis of movement) and an angle α (which iterates from 0 to π/2 in dependence of the current animation frame/time). To give you a better idea of the setup, here is a top-down illustration of what am I trying to achieve (the y axis is irrelevant at this point, joints hierarchy is printed in the bottom left):

alt text

As the image might suggest, I'm trying to translate the pipe from the bottom right quadrant to the top left one, and I want to achieve that by moving the bones/joints along the arch. To place the joints along the arch is fairly easy when you dust-off your trigonometry knowledge. The first joint will always be at the angle for the current animation progress (t):

 JNT_01(x, z) = (Ox + r * cos α(t), Oy + r * sin α(t))

To find where the next joint goes, we need to treat the bone structure as a chord predefined length (original distance between the joints) so that the mesh doesn't get stretched. Thus, to find where we need to place the next joint, we need to find the central angle, then substract it from the current angle α(t) and then place the next joint on the arch of that angle. So:

 ϴ = 2 * arcsin ( dist(JNT_01, JNT_02) / (2 * r) )
 β = α(t) - ϴ
 JNT_02(x, z) = (Ox + r * cos β, Oy + r * sin β)
 

Where dist() represents the distance between the joints. And this repeats until the angle goes bellow 0 degrees at which point I stop moving the other joints along the x axis as I don't want to bend the joints that haven't passed the point around which I'm bending. So far, so good, it distributes the joints correctly. An example of this distribution for the α(1) (full animation angle, π/2) can be seen on this image:

alt text

But in order to have a proper morph/bend those joints need to be rotated as well. And that's where I hit the wall. In theory, the joints should be rotated around the y axis for the angle they are facing the next joint in the chain. That angle can be calculated by subtracting the center angle ϴ from π, and then dividing it by two as both angles on a chord are the same. This would give you the inverse angle of what you need to rotate, so adding the original angle and normalizing it should provide the correct rotation. And indeed it does. So, in theory, the above situation should look like:

alt text

However, since the joints are parented to one another, the end result looks nothing like the above - it pretty much destroys the mesh bending each joint at the inherited + added angle. I've tried setting local rotations, setting rotation before position, copying transformations from null objects positioned correctly (so the problem is definitely with the joint/transformations structure), and pretty much everything in-between, and I just cannot make it work. Everything just turns into a blurb :(

So what am I doing wrong? And am I even on the right track or I needlessly complicated it when there is something that would make this easy peasy?

Sorry for the long text, I just wanted to be as detailed as possible.

Cheers

bend_problem.png (38.2 kB)
bend_problem_translation.png (15.8 kB)
Comment
Add comment · Show 1
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 aldonaletto · Oct 11, 2012 at 04:03 AM 0
Share

The joints are parented to each other? Why not make them "brothers" ins$$anonymous$$d? I mean, child all joints to a single object: this way, the rotation of one joint would not affect any other.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Duke Euphoria · Oct 11, 2012 at 11:41 AM

Perhaps I'm being dim or not understanding the question but it seems to me that a rod with equally spaced hierarchical joints should naturally form a circle if each joint is given the same angle relative to its parent.

There should be no need to manually re-position the joints at all.

If your desired radius is R, your distance between joints is D. Each joint occupies a distance D along the edge of the circle. The angle required is the proportion of a full circle that each joint covers.

     float Circumference=Pi*Radius*2.0f;
     float Angle=360*(JointDistance/Circumference);
 

If each joint is at that angle to its parent the bar will form an arc.

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

11 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

Related Questions

Importing a armature from blender to unity ruins the models rotations -1 Answers

Rigs, performace, optimize game object, expose extra transforms. Questions, questions, questions... 0 Answers

Rotate bones during mecanim animation with generic avatar 1 Answer

How do i find a bone on my character within a script? 2 Answers

How can I have a 0,0,0 rotation value of every single bone inside Unity? 1 Answer


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