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 bummzack · Nov 14, 2013 at 02:50 PM · unity 4.3physics 2d

How to make OnTriggerEnter2D work?

I'm using Unity 4.3 and I was testing the 2D physics. Somehow I can't get a collision response from a kinetic body and a trigger.

Here's the basic setup:

 Player
   +- RigidBody2D (kinematic)
   +- CircleCollider2D

 Trigger
   +- CircleCollider2D (trigger)

There's a OnTriggerEnter2D method on both the Trigger- and the Player-Script, but they don't fire.

If I ditch the 2D physics components and build the exact same setup with the old (3D) physics components, everything works as expected.

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 Mike99 · Nov 15, 2013 at 03:33 PM 0
Share

same here...

avatar image akenaton · Nov 17, 2013 at 02:32 PM 0
Share

Yes i get the same problem In 3D mode i can use kinematic rigidbody which fire OnTriggerEnter In 2D mode rigibody2D kinematic doesn't fire OnTriggerEnter2D

9 Replies

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

Answer by Mike99 · Nov 18, 2013 at 08:43 PM

i've sent a bug report and they answered me they admit the issue and will send the ticket to developers.

Comment
Add comment · Show 5 · 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 bummzack · Feb 18, 2014 at 10:00 AM 2
Share

That was the case. In the meantime the bug was fixed and it works as expected now.

avatar image Oliphant · Feb 22, 2014 at 03:34 AM 0
Share

I still see the same behavior in Unity 4.3.4 - this isn't fixed. Can you point to release notes that claim a fix has been implemented?

avatar image psykojello2 · Mar 25, 2014 at 10:13 PM 0
Share

It still happens for me. I'm curious what the fix is as well.

avatar image Yuda · Mar 28, 2014 at 05:32 AM 0
Share

function OnTriggerExit2D(other : Collider2D) { if(other.tag=="passing") { Score+=1; guiScore.text=""+Score; } }

works

avatar image shopguy · Apr 26, 2014 at 05:04 AM 0
Share

Any news on a fix for this? http://issuetracker.unity3d.com/issues/ontriggerstay2d-is-called-not-properly -- says "Fixed in a future release" -- is that going to be 5.0 or have they not said? I really need OnTriggerEnter2D, and need it to fire only once. OnTriggerExit2D doesn't seem to work either, so setting flag in Enter and clearing on Exit doesn't work.

avatar image
0

Answer by Liens · Nov 15, 2013 at 11:45 PM

In my trial and error tests, it seems as though kinematic rigidbody triggers can't collide in 2D mode. I got it to fire off an OnTriggerEnter2D by turning off "Is Kinematic".

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 bummzack · Nov 17, 2013 at 02:34 PM 0
Share

Yeah I saw that too.. But what if you need the body to be kinematic?

avatar image akenaton · Nov 18, 2013 at 02:54 PM 0
Share

But in unity 3D (4.2) rigidbody (3D) Is kinematic fires OnTriggerEnter and physics does not apply.That's what i want.

rigidbody2D Is kinematic does not fire OnTriggerEnter2D

As my game was working the way i want in 4.2 (3D) i was supposing to work the same way in 4.3 2D. i would like to know why unity $$anonymous$$m made that change or if that is a bug. Sorry for bad english. I'm french.

avatar image
0

Answer by DavidDebnar · Nov 17, 2013 at 02:41 PM

You should read the docs. Rigidbody2D.isKinematic

If this property is set to true then the rigidbody will stop reacting to collisions and applied forces.

Which clearly means, that a kinematic rigidbody is the same as if you didn't have a rigidbody at all. Although, at Rigidbody.isKinematic, the docs say

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore.

which, on the other hand, means, that the rigidbody will not respond to collision by moving away, but still trigger OnTriggerEnter, etc.

The solution?

Set the rigidbody to non-kinematic and use this script.

 #pragma strict
 
 private var g : float;
 
 function OnEnable () {
     g = rigidbody2D.gravityScale;
     rigidbody2D.gravityScale = 0;
 }
 
 function Update () {
     rigidbody2D.velocity = Vector3.zero;
     rigidbody2D.angularVelocity = 0;
 }
 
 function OnDisable () {
     rigidbody2D.gravityScale = g;
 }

With this, it won't move or rotate, but still trigger collision calls.

Edit: Also, if you want the rigidbody to move again, just disable this script instead of disabling isKinematic.

Edit 2: It seems like gravityScale is applied after any other rigidbody calls, so if the rigidbody2D had gravity, the script wouldn't stop it's movement entirely, so I updated the script so that it disables the gravity while it's enabled.

--David

Comment
Add comment · Show 8 · 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 bummzack · Nov 17, 2013 at 02:58 PM 0
Share

This is not a solution, this is a hack. The manual clearly states that kinematic bodies should react to triggers. In fact, the section about Rigidbodies and Is$$anonymous$$inematic exactly describe my use-case.

avatar image DavidDebnar · Nov 17, 2013 at 03:38 PM 0
Share

Well, unless it's a bug on Unity's part, my answer is the solution.

avatar image Liens · Nov 17, 2013 at 10:07 PM 0
Share

According to the documentation (table at bottom), a $$anonymous$$inematic Rigidbody Trigger Collider vs. $$anonymous$$inematic Rigidbody Trigger Collider collision should send a Trigger $$anonymous$$essage.

avatar image DavidDebnar · Nov 17, 2013 at 10:10 PM 0
Share

@Liens, it doesn't say anything about the 2D box collider though, so it's irrelevant.

avatar image Loius · Nov 18, 2013 at 03:15 PM 0
Share

2d and 3d should not be different if they use the same words. A rigidbody should always be a rigidbody, and setting the kinematic value should always have the same effect.

Show more comments
avatar image
0

Answer by akenaton · Nov 18, 2013 at 11:51 PM

Meantime before Unity solve that bug you can simulate 3D in 2D that's working: Player (moving) : add Sprite Renderer. add RigidBody with IsKinematic On (not RigidBody2D). add BoxCollider (not BoxCollider2D) IsTrigger On or Off.

Trigger (wall) : add Sprite Renderer. add BoxCollider with Is Trigger On

On the Script use following:

 void OnTriggerEnter(Collider other)
         {
             if(other.gameObject.name =="Wall")
             {
                 Debug.Log ("Trigger "+ other.gameObject.name);
             }
         }

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
avatar image
0

Answer by BenoitFreslon · Dec 02, 2013 at 11:01 PM

The OnTriggerEnter2D method is never called in my game.

I got 2 sprites with Box collider 2D. The Is Trigger property is set to true but there is no collision detection. I don't have any RigidBody2D component.

     void OnTriggerEnter2D(Collider2D other) {
         Debug.Log (other);
         
     }
     void OnTriggerExit2D(Collider2D other) {
         Debug.Log (other);
     }
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
  • 1
  • 2
  • ›

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

30 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

Related Questions

Unity 4.3 Physics 2d Change Axis 1 Answer

Can't change Rigidbody2D mass 1 Answer

Android app size after installation, 4.3 is 2 times larger than 4.2 0 Answers

Unity 4.3.4 iOS Warnings - iAD and Asset Catalog 0 Answers

One way platform using 2D Colliders? 11 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