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
1
Question by sengel · Jan 28, 2014 at 03:34 AM · collisioncollision detection2d-physics

Can I have a single rigidbody2d that acts as both collider and trigger?

I'm new to unity, and am having what I'm sure must be a simple design issue. I would like my character (a rigidbody2D attached to a couple of collider2Ds) to collide with one set of objects, set A, all of the time, and another set of objects, set B, only some of the time. But even when my character is "not colliding" with set B, I need to know if it is in contact with any member of set B.

Is there a good approach to achieving this within unity's 2D tools?

I've tried layer-based collision detection, changing my character back and forth between a layer that collides with both sets and a layer that collides with only set A. But this method won't tell me when my character is touching (but not "colliding" with in the physics) set B.

I've tried changing the colliders on my character to triggers, but then they don't collide (physically) with set A.

I've tried making a child character that only acts as trigger, but for some reason (possibly because it contains a rigidbody2D of its own) it lags behind the parent character. Creating a parent character and using it to control two sibling characters (one set to 'trigger', one not) had similar spacial issues.

If code is helpful, I can copy it over, but really I think I'm just looking for an algorithm or collision detection tool for a very specific scenario. Thanks for any help!

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

1 Reply

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

Answer by GameVortex · Jan 28, 2014 at 08:47 AM

This is a very interesting question.

Initially I would change all the colliders for set B to be triggers when the character is no longer supposed to collide with them, but this may brake other things in the scene depending on your game (other things will not collide with set B either).

Your suggested solution with a child GameObject is on the correct path. A child GameObject however does not need to have a rigidbody in order to be triggered. So do the same except do not add a rigidbody.

1: Create two layers, one that will collide with Set A and Set B, and another that will only collide with Set B.

2: Set the main character GameObject to the first layer and a collider with collision.

3: Create a child GameObject for the character, set it to the second layer and attach a collider set as trigger.

4: To the child GameObject add a script that handles the OnTrigger events.

Now when the character is no longer supposed to collide with Set B, change the layer to be the second layer. Change it back to the first layer again when it is supposed to collide with Set B.

Again this is your own solution just without the Rigidbody on the child GameObject.

Comment
Add comment · Show 2 · 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 sengel · Jan 28, 2014 at 05:21 PM 0
Share

SOLVED! Hey GameVortex, thanks for the help. Those steps worked perfectly after I fixed a $$anonymous$$or bug in my OnTriggerEnter2D() of the child object (I was referencing a rigidBody2D, which threw an error -- I changed it to reference the parent's rigidBody2D and all was well with the world).

Again, thanks.

avatar image GameVortex · Jan 29, 2014 at 07:36 AM 0
Share

No problem. Glad to hear it worked out. =) Remember to set the question as answered.

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

19 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

Related Questions

Make 2D projectile collide only from the outside 1 Answer

2D collision not registering 1 Answer

How to reliably break contact/collision? 0 Answers

OnCollisionEnter2D(coll: Collision2D) function not being triggered 0 Answers

NavMesh Collision Detection? 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