• 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 Togglesworlh · Nov 15, 2013 at 01:19 AM · physics2d collision

2D Collisions/Triggers are confusing me!

Pre 4.3, I was using 3D physics for my 2D game, constraining any Z movement. It worked as expected: objects had colliders, marked as triggers or colliders, as necessary, and OnCollisionEnter and OnTriggerEnter would be called appropriately.

Post 4.3, I switched to using 2D physics (necessary because the 3D physics annoyingly allowed tunneling, despite continuous collision detection). Now, neither OnCollisionEnter2D nor OnTriggerEnter2D will be called unless the object also has a Rigidbody2D attached. Okay, fine, except for the fact that I want the objects NOT to react to physics (gravity, etc.). So I mark them as kinematic, and suddenly neither of those functions are called again. In other words, at least one of the objects has to be non-kinematic for the collisions/triggers to activate.

Is this as intended, or am I missing something? It seems strange that things would be inconsistent between 2D and 3D (regarding the Rigidbody component).

If it IS as intended, how can I work around this without writing my own collision detection (which would undoubtedly be less efficient than the native Box2D code)?

Comment
Add comment · Show 9
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 Togglesworlh · Nov 17, 2013 at 12:20 AM 0
Share

So I can get around the problem in one case, by just living with the fact that I need a non-kinematic Rigidbody. But then I have objects that NEED to be kinematic because I want to be able to move them on my own, without relying on physics. And then, of course, they won't register collisions.

avatar image gamenovice · Nov 17, 2013 at 02:32 AM 0
Share

could you describe in more detail about why you need certain objects to be kinematic and why certain ones to not react to physics?

avatar image Togglesworlh · Nov 17, 2013 at 02:47 AM 0
Share

Well, I need them to be kinematic because I'm moving them outside the physics engine. It's my understanding that an object HAS to be kinematic if you're doing that, or the physics engine won't properly update the position, etc. Or, at least, that was the case for the 3D engine. Plus, I don't want them to react to collisions, as that would knock them around all willy nilly.

For example, I spawn "explosions" on a mouse click, and some moving object could potentially move through the explosion. I want that to happen, rather than the object being pushed back because it's hitting a Collider. Similarly, I have stationary objects that I want the moving objects to fly over without being obstructed.

Does that help paint a clearer picture?

avatar image Togglesworlh · Nov 17, 2013 at 06:29 AM 0
Share

Hm. So, according to this, I'm doing things correctly.

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

I'd looked at it before, but I figured I'd double check. $$anonymous$$inematic Rigidbody Trigger Colliders should send a trigger message. Of course, this is the 3D collider action matrix (can't find one specific to 2D!), but I don't think it's a wild assumption to assume 2D collisions should act the same.

At this point, I'm starting to think it's just a bug in Unity!

avatar image hapliniste · Nov 19, 2013 at 04:18 PM 0
Share

Hi! I have the same problem. I think collisions should work without phisics (is object A touching object B?) but it looks like this isn't possible...

And onTriggerEnter2D don't work with kinematic RigidBody2D, I think this is a bug.

Personally, I have attached a RigidBody2D to "object B" with no gravity and put that in a layer that dont interact with any other layers ( in Physic2DSettings ).

If someone has more information about it, I'm interested!

avatar image sdgd hapliniste · Nov 19, 2013 at 04:20 PM 0
Share

please don't post answers as showing the issue.

Post a Comment or Question ins$$anonymous$$d.

BTW till now I've never saw 2D physics nor OnTriggerEnter2D

it will not fire if it does not exist.

thanks for your cooperation.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by pleska · Mar 23, 2014 at 09:57 PM

I am not sure if this is how it is supposed to work but I tried all of the possible combinations of both 2D and 3D physics with a simple test of two objects moving in the same plane at each other using Translate(). It seems that there are two different sets of results if you use 2D or 3D. The following are my results in 4.3.4f1:

Setup:

  • Static 2D Object - Only has 2D Collider attached.

  • Kinematic 2D Object - Has 2D Collider attached and 2D rigidbody attached, IsKinematic is checked.

  • Dynamic 2D Object - Has 2D Collider attached and 2D rigidbody attached, IsKinematic is NOT checked.

Note: To prevent gravity and mass I set Gravity Scale to 0 and Mass to min (0.0001)

  • Static 3D Object - Only has 3D Collider attached.

  • Kinematic 3D Object - Has 3D Collider attached and 3D rigidbody attached, IsKinematic is checked.

  • Dynamic 3D Object - Has 3D Collider attached and 3D rigidbody attached, IsKinematic is NOT checked.

Note: To prevent gravity and mass I set Use Gravity to false and Mass to min (1e-07)

Tests and Results

When the grid says Trigger it indicates that I checked the trigger on the collider on that object.

alt text

The results are the following:

  • N - No trigger or collider event fired.

  • T - The OnTriggerEnter2D() event fired in 2D and the OnTriggerEnter() event fired in 3D.

  • B - The physics engine caused a blocking so they couldn't pass through each other. OnCollisionEnter2D() fired in 2D and OnCollisionEnter() fired in 3D.

  • T - The OnTriggerEnter2D() event fired in 2D and the OnTriggerEnter() event fired in 3D but in 2D it fired multiple times as they passed through each other*.

Differences

  • Yellow Area - Shows a difference in 2D where multiple enter events are firing if you have a dynamic pass through a static one. This I think is a bug that has been reported and I think I have seen someone is working on it.

  • Red Area - This is the big area of confusion right now it seems but the use of Box2D as part of the 2D physics engine is causing Kinematic interactions with Static and Kinematic objects to not react in 2D where they do in 3D. It seems you can kind of work around this by making one of the objects dynamic and then disabling all the mass and gravity in 2D. Hopefully this is something they plan to change in the future.

I hope this helps.

Paul


2d and 3d physics.png (22.4 kB)
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 Kirlim · Mar 23, 2014 at 10:46 PM 0
Share

By now I believe that most of these differences are really intended by the dev $$anonymous$$m. Too late to change that now that most 2d games are working on these assumptions, too. If the 2d game needs to run away from realistic physics and use lots and lots of kinematics body, I advise to use 3d physics ins$$anonymous$$d if possible (shouldn't change performance, afaik) or simply build up your own 2d collision system. I'm quite happy with a sweep sat algorithm. Learned a lot of math magic with it, too...

avatar image ohboyotero · Apr 18, 2014 at 11:45 PM 0
Share

Awesome summary! Thanks a ton. I'd upvote the crap out of this answer but I don't have enough rep :(

avatar image darthbator · May 08, 2014 at 04:10 AM 0
Share

This is one of the best explorations of answer that I didn't want to read :_| I really wish we could have kinematic bodies send messages back and forth for 2D physics.

avatar image
0

Answer by keely · Aug 01, 2014 at 08:20 AM

This problem has been fixed in Unity 4.5 and as far as triggers and static/kinematic/dynamic goes, our 2D physics engine should behave like 3D.

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.

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

26 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

Related Questions

2D 360 degress platformer example needed 0 Answers

Why Does Object Keep Getting Faster? 1 Answer

bow and arrow game 6 Answers

Setting Wheelcollider BrakeTorque to 0 does not release brake 0 Answers

Make character face toward MOUSE /Raycast. 2D Left/Right 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