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 Jurassic · Jul 20, 2014 at 02:23 AM · collisioncollidertrigger

OnTriggerEnter firing twice

Hey all, pulling my hair out over this one. I have searched and seen this same topic posted many, many times and tried many workarounds/solutions and none have worked. The more frustrating thing is that my scene is relatively simple, so there aren't a whole lot of places where things could go wrong.

I have two gameObjects I'm working with here - the player, who's only collider is a PlayerController, who has one child object that absolutely does not have any colliders on it. (I have checked and checked again, and even deleted the object), and a Door. The door has a single Box Collider on it that is set as a Trigger and no child objects.

Below is the script on the door. As you can see, am I even disabling and then destroying the door's Collider after executing my script, but it STILL fires a second time. The Debug Log always returns the name of the door and the name of the player.

Please help. I'm going insane, lol.

     //    Move the player through rooms when he goes through doors.
     void OnTriggerEnter (Collider other) {
 
         if(other.gameObject == player) {
 
         Debug.Log ("Trigger at "+gameObject.collider.name+"+"+other.name);
 
             switch(doordirection){
 
             case(DoorDirection.North):
                 roomController.ChangeRooms(roomController.currentPlayerLocX, roomController.currentPlayerLocY+1);
                 player.transform.position = new Vector3(0, 1.5f, -14f);
                 break;
 
             case(DoorDirection.South):
                 roomController.ChangeRooms(roomController.currentPlayerLocX, roomController.currentPlayerLocY-1);
                 player.transform.position = new Vector3(0, 1.5f, 14f);
                 break;
 
             case(DoorDirection.East):
                 roomController.ChangeRooms(roomController.currentPlayerLocX+1, roomController.currentPlayerLocY);
                 player.transform.position = new Vector3(-16.5f, 1.5f, 0);
                 break;
 
             case(DoorDirection.West):
                 roomController.ChangeRooms(roomController.currentPlayerLocX-1, roomController.currentPlayerLocY);
                 player.transform.position = new Vector3(16.5f, 1.5f, 0);
                 break;
             }

         gameObject.collider.enabled = false;
         Destroy(gameObject);
         }
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 tw1st3d · Jul 20, 2014 at 02:24 AM 0
Share

Where are you getting the doordirection variable from?

avatar image Owen-Reynolds · Jul 20, 2014 at 03:17 PM 0
Share

Hmm...wonder if moving the player might be firing the second one? Try printing more -- time, position of player.

Since that child object is bugging you, change the player into just a ball (that drops into the door.) $$anonymous$$ake the example simpler and simpler until the double-fire goes away. Then add back until it returns.

avatar image Jurassic · Jul 20, 2014 at 06:52 PM 0
Share

Just tested removing the movement, no dice. I added a time and position to the debug and the second activation is happening 0.02 seconds after the first and at the same location.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jul 20, 2014 at 08:07 PM

0.02 is one physics step. Destroy is known to take some time to really destroy it, but enabled=false should take care of that. Could try SetActive. Or add a bool to prevent refiring.

If it was me, I'd suspect an extra something. Would want to put this script on a fresh cube in a fresh scene, just to be sure I was adding an extra door or something.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make work a collision when is invisible? 3 Answers

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

Triggering platform animation on colliding with Button 0 Answers

NPCs collide with collider but player does not 1 Answer

Prevent shooting when gun is inside wall 1 Answer


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