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 Ethanthecrazy · Mar 06, 2014 at 07:09 AM · rigidbody2dcollider2dparentingcollisions

How do I fix 2d collisions when I parent one object to another?

Object A Object B

I have a script that sets A's transfrom.parent to B's transform when A collides with B. Up until this point object A has a 2d collider and a 2d rigidbody. Object B has a collider and is a child of an object with a kinematic 2d rigidbody. When the parenting occurs, I destroy the rigidbody on object A. Now other 2d colliders pass through object A's collider, even though its a normal collider at best, or a static collider at worst.

But if I go into the editor during play and move the object A manually after it has been parented, objects will start colliding with object A again.

I would like to have collisions work for object A without having to manually move it.

Here is the code:

 tarGameObject.transform.parent = gameObject.transform;
 tarGameObject.transform.localPosition = new Vector3();
 tarGameObject.transform.localRotation = Quaternion.identity;
 Destroy( tarGameObject.rigidbody2D );

Thanks for your time.

Comment
Add comment · Show 4
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 Ethanthecrazy · Mar 06, 2014 at 07:11 AM 0
Share

If I disable and enable the 2d collider on object A, collisions work again. I noticed that the green box for collision volumes in the editor is missing up until I re-enable it manually, but the code

tarGameObject.collider2D.enabled = false; tarGameObject.collider2D.enabled = true;

does not appear to work.

avatar image highpockets · Mar 06, 2014 at 07:33 AM 0
Share

I don't know if this will help you in your situation, but this is what I have done in a similar case:

  1. Object A collides with object B, Object A becomes the parent of Object B.

  2. Object B's rigidbody is set to is$$anonymous$$inematic and it's collider is set to false (only because I need to enable it in the future )

  3. Resize Object A's collider to envelope both objects.

Now they should both be influenced by only the one collider. Hope that helps

avatar image Ethanthecrazy · Mar 06, 2014 at 03:07 PM 0
Share

I really would prefer that each object have its own collider. A & B each have their own set of behaviors, and it would be prohibitive to have to write code to handle that. I have tried setting the child object's rigidbody to kinimatic, but I get bizzare result when the parent object rotates.

avatar image highpockets · Mar 06, 2014 at 07:07 PM 0
Share

Right, I had troubles with what you're dealing with myself. I tried using a Fixed Joint, but there was too much movement in the joint, so I had to do what I mentioned above to resolve the issue as nothing else was working. I'm looking forward to seeing if someone has a different solution. One other option was a configurable joint and customizing that to, in my case, not rotate by means of the joint at all, but I found that it was way to robust a feature for what I needed. Hope you find something and if you find it yourself without someone answering, post it as an answer as I'm sure I wouldn't be the only one interested in hearing about it.

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

21 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

Related Questions

Why do GameObjects need Rigidbodies to collide? 0 Answers

Simple Rigidbody2D movement and jump 0 Answers

Why doesn't my hexagonal collision fit properly? 1 Answer

OnCollision2D never worked 0 Answers

Best solution for making arc collider 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