• 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 /
  • Help Room /
avatar image
0
Question by UserNameIsAlredyTaken · Oct 07, 2018 at 07:37 PM · rotationrigidbodychild objectphisics

How does child's rigid body affect parent's rigidbody?

I had a player with such hierarchy: alt text

where Player is a body, Weapon is just an EmptyObject that represents a pivot point for Barrel which is cylinder. So this is how it looks like: alt text Player and Barrel had their own rigidbodyes and raise of Barrel was controlled by script attached to Player:

 private void FixedUpdate()
     {
         Raise();
     }
 
     private void Raise()
     {
         var raiseValue = m_RaisingValue * m_WeaponRaisingSpeed * Time.deltaTime;    
         
         if ((raiseValue + m_WeaponTransform.eulerAngles.x) <= m_BotAngelConstraint || (raiseValue + m_WeaponTransform.eulerAngles.x) >= m_TopAngelConstraint) 
         {
             m_WeaponTransform.localRotation = Quaternion.Euler(raiseValue + m_WeaponTransform.eulerAngles.x, 0f, 0f);
         }
     }   

The problem was that Barrel's collider didn't work and could pass thru walls. Then I read that it' bad practice to have rigidbodyes on a parent and a child objects and deleted Barrel's rigidbody. It solved the problem with the collider but changed behavior of Player. Now after some movement it starts to change it's rotation despite it has constraints to freeze rotation on X and Z axis in it's rigidbody, and the Barrel's raise became uncontrollable, it doesn't stay still when I don't control it and Barrels's end strives to fall down.

The question is how to make Barrel to stay still when I don't control it and Player not to rotate on it's fixed axis?

безымянныи1.png (107.1 kB)
безымянныи.png (2.8 kB)
Comment
Add comment · Show 2
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 LeonardNS · Oct 07, 2018 at 10:56 PM 0
Share

I can't say I fully understand your problem, but if you only ever change your character's position, and rotation with a script - in other words, you don't use velocity or rotation velocity of rigidbody - it might be a good idea to set the whole rigidbody to kinematic.

avatar image UserNameIsAlredyTaken LeonardNS · Oct 08, 2018 at 07:18 AM 0
Share

It's a good option and I even had tried it, and everything was working fine, but I need it to be non kinematic because otherwise it couldn't jump and bounce off each other.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by LeonardNS · Oct 08, 2018 at 10:48 AM

What about rotation? Do you use the rigidbody rotation or only update rotation via scripts? As far as I know, if you lock the rotation on the y-axis as well you get the best of both worlds. Your rotation problem should be solved and they can still bounce off each other. Rotation in collisions is still gone, but that is quite difficult to keep track of anyway.

EDIT: Converted to answer

Comment
Add comment · Show 3 · 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 UserNameIsAlredyTaken · Oct 08, 2018 at 05:46 PM 0
Share

I locked the rotation on the y-axis on players rigidbody and it's solved both problems! But I still don't understand how does it work. $$anonymous$$y assumption: y constraint on parent's rigid body locked the rotation on the y-axis on the child (Weapon) which now can't go up and down freely and became controllable. Am I right? So the question is, how to lock child's freely rotation without y-axis constraint on the parent's rigidbody and without adding rigidbody to the child?

avatar image LeonardNS UserNameIsAlredyTaken · Oct 08, 2018 at 05:58 PM 0
Share

The problem you had with the barrel sounds really bizarre. I have no idea how locking the y rotation solved it.

avatar image UserNameIsAlredyTaken LeonardNS · Oct 09, 2018 at 08:18 AM 0
Share

Thank you anyway.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

209 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 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 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

Rotate Rigidbody towards target rotation using AddTorque() 0 Answers

i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers

Rotate GameObject based on RigidBody Velocity 1 Answer

Rotations on "picked up" object 0 Answers

Cannot rotate RigidBody, 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