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
2
Question by ronronmx · Jun 04, 2012 at 04:45 AM · collisiontrigger

OnTriggerEnter - Same collider triggers multiple times?, is size a factor?

I have a collider set as a trigger on my moving rigidbody, which is the size of the rigidbody. I have another trigger, which detects when my rigidbody goes through, and prints the name of the rigidbody collider.

When the rigidbody collider enters the trigger, it prints the rigidbody's name more then once (up to 5 times). But if I reduce the size of the rigidbody collider so that it's much smaller then the trigger checking for it, it only prints the name once.

Does the size of the other collider matter? If the collider entering the trigger is bigger then said trigger, is it going to detect the collision more then once?

Thanks for your time! Stephane

Comment
Add comment · Show 3
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 The1nk · Jun 11, 2012 at 10:14 PM 0
Share

After the trigger, are you doing anything in code to end the collision (i.e., removing one of the GameObjects) ?

avatar image The1nk · Jun 12, 2012 at 01:10 AM 0
Share

@kolban - I wish I had high enough rep, level, whatever it's called on this platform, to upvote that comment. xD

avatar image ronronmx · Jun 13, 2012 at 04:49 AM 0
Share

No I'm not, I just detect OnTriggerEnter() and that's it. I have tried using a bool to tell the trigger that it's been triggered already, but it still happens a $$anonymous$$imum of twice.

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bodec · Jun 12, 2012 at 04:36 AM

This is a problem i recently had and asked about and was asked before here is the link to the answer. "Edited from here." here is the chunk of code i have been using with the most up to date version of unity and it seems to be working fine.

function OnTriggerEnter(col : Collider){

 if(col.tag == "waypoint" && !isTriggered ){
     isTriggered = true;
     ChangeWayPoint();
     
 }

}

function ChangeWayPoint(){

 if(waypoints != 11){
     curWayPoint ++;
     isTriggered= false;
     print(curWayPoint);
 


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 ronronmx · Jun 13, 2012 at 04:50 AM 1
Share

Yes I tried setting a flag like in the example, but like I said above, it still happens twice no matter what I do...weird.

avatar image javanoob · Mar 02, 2013 at 09:57 PM 0
Share

Any ideas on this because I have made 6 diiferent checkpoint systems and they all fail from this multiple trigerr thing :( driven me nuts for months coz I thought I was the one doing it wrong fot months :(

avatar image
0

Answer by vekkna · Apr 06, 2014 at 09:22 PM

I had a similar problem today. It turned out I somehow had two "Circle Collider 2D components attached to the offending object. Removing the extra one via the inspector got rid of the extra onTriggerEnter.

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 Gunarvingren GP · Jul 12, 2015 at 01:56 PM

In my case the problem was that both colliders (player and enemy) was flagged as "IsTrigger", this way enemy collider fire OnTriggerEnter, then in the same time player collider also fire OnTriggerEnter. To solve that i just set the player flag "IsTrigger" to false.

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 Gunarvingren GP · Jul 12, 2015 at 01:56 PM

Here is the definitive solution i found to this problem:

 void OnTriggerEnter(Collider enemy) {
     enemy.hitCount++;
     if(enemy.hitCount==1){
         enemy.doStuff();
     }
 }
 
 void OnTriggerExit(Collider enemy) {
     enemy.hitCount--;
     if(enemy.hitCount<0){
         enemy.hitCount=0;
     }
 }

In this case go to the enemy script and add the variable:

public int hitCount=0;

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Terrain doesn't collide with my mesh 1 Answer

Scoring Issue 0 Answers

Trigger Enter and Exit not working properly? 2 Answers

Question about collision and trigger 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