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
1
Question by war_man333 · Oct 27, 2015 at 11:29 AM · rigidbody2djoints

My flipped character ragdoll has wrong hingejoint anchor positions

I'm working on an old endless zombie-killing sidescrolling runner-esque game. I did not start this project back in the day.

Dynamic Ragdolls

I recently added ragdolls to the game. By ragdolls I mean a collection of rigidbodies which are connected to each other through hingejoints. Since the zombies are basically animated boxes with 1 rigidbody each, my approach was to create the ragdoll 'dynamically', so I turn an animated box into a 'ragdoll'.

Flipping

Ragdolls work perfectly fine. Untill you flip the character. The game flips characters by inverting the x-axis. I also tried 'flipping' the character by rotating him around the Y-axis, but the ragdollifying results were the same.

I think the solution is either flipping zombies in another fashion, or somehow, magically fixing the anchor points when applying the hingejoints.

Code

The entire code for the zombie ragdoller-class is here: http://pastebin.com/99ZHWetZ

Here's a snippet of the HingeJoint2D-adding code:

     private void ApplyHingeJoints()
     {
         Rigidbody2D rb2d_torso = Torso.GetComponent<Rigidbody2D>();
 
         HingeJoint2D leftarm_joint = LeftArm.AddComponent<HingeJoint2D>();
         HingeJoint2D rightarm_joint = RightArm.AddComponent<HingeJoint2D>();
         leftarm_joint.connectedBody = rb2d_torso;
         rightarm_joint.connectedBody = rb2d_torso;
 
         HingeJoint2D lefthand_joint = LeftHand.AddComponent<HingeJoint2D>();
         HingeJoint2D righthand_joint = RightHand.AddComponent<HingeJoint2D>();
         lefthand_joint.connectedBody = LeftArm.GetComponent<Rigidbody2D>();
         righthand_joint.connectedBody = RightArm.GetComponent<Rigidbody2D>();
         JointAngleLimits2D handAngleLimits = new JointAngleLimits2D();
         handAngleLimits.min = -30;
         handAngleLimits.max = 30;
         lefthand_joint.limits = righthand_joint.limits = handAngleLimits;
         lefthand_joint.useLimits = righthand_joint.useLimits = true;
 
         HingeJoint2D leftleg_joint = LeftLeg.AddComponent<HingeJoint2D>();
         HingeJoint2D rightleg_joint = RightLeg.AddComponent<HingeJoint2D>();
         leftleg_joint.connectedBody = rightleg_joint.connectedBody = rb2d_torso;
         JointAngleLimits2D legAngleLimits = new JointAngleLimits2D();
         handAngleLimits.min = 0;
         handAngleLimits.max = 200;
         leftleg_joint.limits = righthand_joint.limits = legAngleLimits;
         leftleg_joint.useLimits = rightleg_joint.useLimits = true;
         rightarm_joint.connectedAnchor = new Vector2(-0.15f, 4.15f);
         leftarm_joint.connectedAnchor = new Vector2(-0.9f, 4f);
         lefthand_joint.connectedAnchor = righthand_joint.connectedAnchor = new Vector2(-0.15f, -4.2f);
     }

The flipping-code located in another class looks like this:

     void Flip()
     {
         // Multiply the player's x local scale by -1
         
         Vector3 scale = transform.localScale;
         scale.x *= -1;
         transform.localScale = scale;
         
         //transform.Rotate(new Vector3(0, 180, 0));
 
 
         // Invert the rotation of the particle effect
         bloodSplatter.startRotation *= -1;
     }

Here's the unfortunate result from killing a flipped zombie. Red lines are arms, purple are hands, blue is torso and green are legs. The hands are supposed to be connected to the arms and the arms are supposed to be connected to the torso. alt text

If you need anything, please just comment. Thanks in advance.

zombie.png (88.1 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 majman · Jan 17, 2016 at 03:21 PM 0
Share

I've been having the same exact issue... was hoping there was an in-editor approach around this, but still have yet to find anything.

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

32 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

Related Questions

Rigidbody2D rotation spinning wildly when attaching by joint to another Rigidbody2D 0 Answers

Problem with wheelJoint2D car rotations - my car needs to be able to do double jumps and mid-air rotations. 0 Answers

How to acquire and use WheelJoint2D jointSpeed in my own formula 0 Answers

2D muscle joint? 0 Answers

How to get suspension or wheels collider with the new 2D unity tools 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