Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 aespielberg_unity · Jan 05, 2018 at 09:59 AM · scalingjointskinematiccapsuledynamics

General construction of kinematic trees with scaled capsules

I'm trying to generally create a kinematic tree out of capsules. I know that capsules are effectively 2x1x1 objects, the 2 being length, which makes the bookkeeping here a little annoying. For each capsule, I want to be able to specify:

  • A length - this is the length oft he capsule. We'll assume the other dimensions are unchanged.

  • A position and orientation in which the capsule is connected to a specified...

  • Parent capsule. That is, unless it's the root of the tree.

  • The relative location of the joint in the parent and child frames.

In essence, I'm trying to make something that can eventually generate characters from urdfs.

I'm trying to link these all up with joints, so I can actuate this character and do some physical experiments with it. While I find this works okay when I don't scale my capsules, things start to break once I do.

To get started, I've tried specifying a character semi-algorithmically with the above-specified inputs. Right now, there's just a head, a torso, and a forearm.

The torso code extrapolates fine beyond unit length. I can rescale it to whatever I want and it's just fine. But the arm has a couple of problems, which may or not be related.

First, the joint is slightly off at unit length, to the left.

Unit length. The axis of rotation is a little bit to the left.

alt text

Meanwhile, while the length and positioning looks fine when I make it longer, the joint is all the way to the right:

alt text

I'm pasting my code below. Is anyone able to explain to me what I'm doing wrong, and how I can algorithmically create a kinematic tree of scaled capsules? Beyond the specification of the positions and orientations of each capsule and their joints, I feel like this should be very short and simple script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Runner : MonoBehaviour {
 
     //creates a super simple rigid biped as 10 limbs
     //head
     //torso
     //two three linked legs
     //two single linked arms
 
     // Use this for initialization
 
     List<float> transforms;
     List<GameObject> links; 
 
     void Start () {
 
         Vector3 global_position = new Vector3(0.0f, 8.0f, 0.0f);
 
         Dictionary<GameObject, float> lengths = new Dictionary<GameObject, float>();
         Dictionary<GameObject, Vector3> positions = new Dictionary<GameObject, Vector3>();
         Dictionary<GameObject, Quaternion> rotations = new Dictionary<GameObject, Quaternion>();
         Dictionary<GameObject, Vector3> parentJointPosition = new Dictionary<GameObject, Vector3>();
         Dictionary<GameObject, Vector3> axis = new Dictionary<GameObject, Vector3>();
 
 
 
 
         Dictionary<GameObject, GameObject> parents = new Dictionary<GameObject, GameObject>();
 
         GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
 
         //turn on physics
         capsule.AddComponent<Rigidbody>();
         capsule.GetComponent<Rigidbody>().SetDensity(1000f);
 
         //instantiate the biped:
         GameObject head = Instantiate(capsule);
         GameObject torso = Instantiate(capsule);
         GameObject left_arm = Instantiate(capsule);
 
 
         lengths[head] = 1.0f;
         positions[head] = global_position;
         rotations[head] = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
         parents[head] = null;
 
         parents[torso] = head;
         lengths[torso] = 3.0f;
         //TODO: generalize this code
         positions[torso] = positions[parents[torso]] + Vector3.down * (lengths[parents[torso]] + lengths[torso]); // a /2.0f factors out since capsules are naturally 2x1x1, so the length is actually twice its value
         rotations[torso] = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
         parentJointPosition[torso] = positions[torso] + Vector3.up * lengths[torso];// a /2.0f factors out since capsules are naturally 2x1x1, so the length is actually twice its value
         axis[torso] = Vector3.back;
 
         
         parents[left_arm] = torso;
         lengths[left_arm] = 3.0f;
         //TODO: generalize this code
         //want it to be at top of the torso, to the left so it's not intersecting
         positions[left_arm] = positions[parents[left_arm]] + Vector3.up * (lengths[parents[left_arm]]) + Vector3.left * lengths[left_arm];
 
         rotations[left_arm] = Quaternion.Euler(new Vector3(0.0f, 0.0f, -90.0f));
         parentJointPosition[left_arm] = positions[left_arm] + Vector3.up * lengths[left_arm];
         axis[left_arm] = Vector3.left;
         
         head.name = "head";
         torso.name = "torso";
         
         left_arm.name = "left_arm";
 
 
         Destroy(capsule);
 
 
         links = new List<GameObject> { head, torso, left_arm };
 
 
 
         foreach (GameObject link in links)
         {
 
 
             link.transform.localPosition = positions[link];
             link.GetComponent<Rigidbody>().velocity = Vector3.zero;
             link.transform.localRotation = rotations[link];
             
 
 
             //hinge it up if necessary
             if (parents[link] != null) { 
 
                 HingeJoint hinge = link.AddComponent<HingeJoint>();
                 hinge.connectedBody = parents[link].GetComponent<Rigidbody>();
 
                 
                 hinge.anchor = (parentJointPosition[link] - positions[link]);
                 Debug.Log(hinge.anchor);
 
                 /*
                  * if we want to we should be able to specify this manually...
                 hinge.autoConfigureConnectedAnchor = false;
                 hinge.connectedAnchor = (parentJointPosition[link] - positions[parents[link]]);
                 */
 
                 Debug.Log(parentJointPosition[link]);
                 Debug.Log(positions[parents[link]]);
                 Debug.Log(hinge.connectedAnchor);
             
 
                 //TODO: generalize
                 hinge.axis = Vector3.left;
 
                 hinge.breakForce = float.PositiveInfinity;
                 hinge.breakTorque = float.PositiveInfinity;
             }
 
 
         }
 
         
         foreach (GameObject link in links)
         {
 
             link.transform.localScale = (Vector3.one + Vector3.up * (lengths[link] - 1.0f));
 
         }
         
 
 
     }
     
     // Update is called once per frame
     void Update () {
         foreach (GameObject link in links)
         {
             Debug.Log(link.name + ": " + link.transform.localPosition);
         }
     }
 }


armlength3.png (409.8 kB)
unitarm.jpg (518.1 kB)
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

71 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

Related Questions

Stretchy legs and collision 1 Answer

Can a jointed, non-kinematic rigidbody snap straight to a kinematic rigidbody's position? 1 Answer

joint problem maya to unity 0 Answers

network of rigidbodies cannot have more than one kinematic body and work well? 0 Answers

Joint (with is kinematic) work like a child, 100% fixed, without little bounces? 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