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 $$anonymous$$ · Jun 05, 2016 at 03:53 PM · rigidbody2ddisableboxcollider2dontriggerenter2d

Boxcollider2D, Trigger not working

Hello,

as first i know there are many questions like mine but I already tried what i found.

So, I'm using Unity 5.3.5f1 and im trying to get trigger enter on 2D box.

I'm "shooting" 2D circle with circle collider and non kinematic rigidbody to static box collider (everything 2d) . If i dont set "is trigger" they bounce but dont react to "oncollisionenter2d" if they are (those boxes) "is trigger" enabled they dont react to "ontriggerenter2d"

Any help? I'm desperate :D Thanks in advance :)

alt text alt text

1.png (91.5 kB)
2.png (25.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 Kimi073 · Jun 05, 2016 at 04:18 PM 1
Share

Try making the circle has the "is kinematic" enabled and the rectangle has it disabled. In the older version of Unity that I have used, sometimes two object those have "is kinematic" both enabled or disabled don't react to each other. Plus, check if your script is written as you desired.

avatar image $$anonymous$$ Kimi073 · Jun 06, 2016 at 05:40 PM 0
Share

@$$anonymous$$imi from docs i found this "Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."

 function OnTriggerEnter2D(other: Collider2D){
     Debug.Log("Trigger: "+other);
     
 }
 
 function OnCollisionEnter2D(coll: Collision2D){
     Debug.Log("Collision: "+coll);    
 }

+code of my trigger/collision (and inspector u can see in post) any help?

2 Replies

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

Answer by brunocoimbra · Jun 06, 2016 at 06:05 PM

You need to attach your script to your trigger...

By your inspector, you did NOT attached the script!

If you did, please update your post with your ACTUAL script and inspector! We can't help if you don'y give us any REAL info.

Comment
Add comment · Show 1 · 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 $$anonymous$$ · Jun 06, 2016 at 06:08 PM 0
Share

Okay, i found problem. I expected my code will accept any collision from any object attached to any other object. So i have to run script to every trigger enabled object to get message. Thank you.

Is there any possibility to do that without attaching code (new one) to every platform and do it somehow globally?

avatar image
0

Answer by Dibbie · Jun 05, 2016 at 04:27 PM

Cases matter in variable names - so set the "Is Trigger" boolean/checkbox in the inspector ON for your bullet.

In your code, im assuming thats attached to your bullet, it may look something like this (untested code - C#):

 OnTriggerEnter2D (Collider2D col){
 //destroy your target you collided with
 Destroy(col.gameObject);
 //destroy yourself
 Destroy(this.gameObject);
 }
 
 ////or a more specific check
 //OnTriggerEnter2D (Collider2D col){
 //if(col.gameObject.tag == "Enemy"){
 ////destroy your target
 //Destory(col.gameObject);
 ////destroy yourself
 //Destroy(this.gameObject);
 //}

In the second example (that is commented out), the "Enemy" tag is something youd have to create in the inspector, clicking on any object and going to the inspector, near the top left where it says "Tag" and normally it will be some default tag, click on the drop-down, and create a new tag. Make sure the name, spelling, and capitalization of the tag you create in the inspector, reflect the same in your code.

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 Kimi073 · Jun 05, 2016 at 04:32 PM 0
Share

Your example script is correct. And by the way thanks for adding the "tag" issue, I forgot that :P

avatar image $$anonymous$$ · Jun 05, 2016 at 10:50 PM 0
Share

haha i accidentaly posted 2 same pictures ill change it tommorow now im on ntb.. of course i have is trigger enabled on box.. i will try kimi's "is$$anonymous$$inematic" but im not sure cuz i think i already did this ...the problem is .. i HAVE istrigger enabled, i tried is$$anonymous$$inematic on/off (but only projectile has rigidbody, not both) and i did

   function ontriggerenter(collcollider2d){
        debug.log("blabla");
   } //now its not 100% correct by syntax

and it does really nothing.. it just dont trigger :/ i had that ontriggerenter function at my previous game with older version which worked like a charm :/ now i did same thing and nothing here :(

avatar image $$anonymous$$ · Jun 05, 2016 at 10:51 PM 0
Share
  • @dibbie i dont want destroy i have my own code to do something else so answer is out of topic bit.. its nothing with tags and destroying etc, its about unity is not getting triggerEnter event

avatar image tanoshimi $$anonymous$$ · Jun 06, 2016 at 05:54 PM 0
Share

Did you read @dibbie's answer? Your code is complete nonsense:

 function ontriggerenter(collcollider2d){
     debug.log("blabla");
 }

  • OnTriggerEnter, not ontriggerenter.

  • But, seeing as you appear to be trying to use 2D physics, this should actually be OnTriggerEnter2D.

  • collcollider2d? probably coll : Collider2D

  • Debug.Log, not debug.log

https://unity3d.com/learn/tutorials/topics/physics/colliders-triggers

avatar image $$anonymous$$ tanoshimi · Jun 06, 2016 at 06:04 PM -1
Share

$$anonymous$$ister! Did u read note? Code is not correct by syntax..

 function OnTriggerEnter2D(other: Collider2D){
     Debug.Log("Trigger: "+other);
     
 }
 
 function OnCollisionEnter2D(coll: Collision2D){
     Debug.Log("Collision: "+coll);    
 }

  • this is my real code

please! i told i know how to do triggers, i already did game using them, i used same way and something is wrong.. im sorry for my reaction but im irritated

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

BoxCollider2D, Trigger not working 1 Answer

Why is my 2D Collision Delaying or Missing? 0 Answers

Stack/Tower of inelastic collider2D + rigidbody2D bounce when collide with ground, single collider2D + rigidbody2D does not bounce 1 Answer

BoxCollider error from C# to UnityScript 0 Answers

2D box collision not working,2d Box Collider not working 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