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 rogvc · Jan 03, 2020 at 04:37 PM · collisionparent

Parenting an object causes Collider2D to stop working

Hey there, I have a question about parenting and colliders.

I have player, box and wall game objects. Both player and box have their own box collider 2D and rigidbody, both dynamic (at first) and both work just fine and are confined within the walls no problem.

However, I implemented a grabbing function in which the player grabs the box while a key is pressed. I'm using this code to do that:

 if (m_IsHoldingGrab)
    {
        grabbed.transform.position = transform.position;
        grabbed.transform.parent = transform;
        grabbed.GetComponent<Rigidbody2D>().isKinematic = true;
    }
 
    else
    {
        grabbed.transform.parent = null;
        grabbed.GetComponent<Rigidbody2D>().isKinematic = false;
    }

Grabbing works just fine, but suddenly my box can't collide with anything while it's parented to the player. Is there a way to make it still collide even thought it's parented?

P.S.: Here's the Rigidbody2D definitions for my box and player:

----Box: alt text

----Player: alt text

Thanks!

box.png (19.4 kB)
player.png (19.1 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 TreyH · Jan 03, 2020 at 05:04 PM 1
Share

Well the parenting probably isn't your issue here, but this might be:

 grabbed.GetComponent<Rigidbody2D>().is$$anonymous$$inematic = true;


From the documentation: If is$$anonymous$$inematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore.

avatar image Lairinus · Jan 06, 2020 at 05:03 AM 1
Share

@TreyH is correct as this may be the issue. Setting an object to $$anonymous$$inematic makes it so that it doesn't react to physics.

Another potential issue is that I see you're moving the object using its' transform. You'll want to use Rigidbody2D for this; directly moving a transform will place the object wherever you tell it without taking collision into consideration.

For further reading: https://answers.unity.com/questions/215377/transformtranslate-vs-rigidbodymoveposition.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rogvc · Jan 06, 2020 at 05:50 AM

Thanks for the replies! I fixed it by not changing the rigidbody's body type at all and changing the gravity scale instead. Works like a charm now.

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

178 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

Related Questions

Simple Parenting Question 1 Answer

How to destroy a parent object when child object is collided 1 Answer

Need to get parent Object after collision 1 Answer

OnCollisionEnter not registering on children 0 Answers

How to detect child object collisions on parent 3 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