• 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
Question by Teyandee · Jul 07, 2014 at 07:35 PM · rigidbodycollidertriggerontriggerenter

OnTriggerEnter fails to activate

I have an object tagged as "Buster" flying through a trigger that should detect objects with the tag "Buster" and respond, but it does not. I have seen in other similar questions asked here the solution was found when they added a rigidbody to one of the objects. So I have added a rigidbody to the "Buster". Raycasts Hit Trigger is true. The trigger is a sphere collider with Is Trigger set to true.

This is the trigger script:


 #pragma strict
 
 public var HP : int;
 
 function Start () {
 
 }
 
 function Update () {
     
 }
 
 function OnTriggerEnter (other : Collider) {
     if(other.tag == "Buster"){
         HP = (HP -1);
     }
 }



This is the "Buster" script:


 #pragma strict
 
 private var left : boolean;
 public var time : float;
 public var speed : float;
 private var counter : float;
 public var xPosition : float;
 public var yPosition : float;
 
 function Start () {
 
     transform.position.x += xPosition;
     transform.position.y += yPosition;
     left = true;
     counter = 0;
 
 }
 
 function Update () {
 
     if (left) {
         if (time > counter){
             transform.position.x -= speed;
             counter++;
         }
         else {
             Destroy(this.gameObject);
         }
     }
 
     else {
         if (time > counter){
             transform.position.x += speed;
             counter++;
         }
         else {
             Destroy(this.gameObject);
         }
     }
     
 }



Comment

People who like this

0 Show 6
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 Firedan1176 · Jul 07, 2014 at 07:37 PM 1
Share

Did you try adding a Debug.Log message in OnTriggerEnter to see if it were firing?

avatar image screenname_taken · Jul 07, 2014 at 07:57 PM 0
Share

I can think of two things. 1, the trigger is so think/object is moving so fast, that when the object is passing through the trigger, Unity isn't "looking" at it. 2, typo perhaps at the tag?

avatar image Teyandee · Jul 07, 2014 at 09:35 PM 0
Share

I can see it isn't firing because the HP variable isn't lowering. I have the Inspector window up as I play test. I did a look over on the tag and script, there is no typo on the tag.

It could possibly be going too fast for it. I tried slowing it down to a crawl and it still isn't being triggered.

Thanks for the quick responses, I appreciate it!

avatar image tanoshimi · Jul 07, 2014 at 09:38 PM 0
Share

What sort of collider does Buster have on it?

avatar image legion_44 · Jul 07, 2014 at 10:01 PM 0
Share

try other.CompareTag("Buster") instead of other.tag

Show more comments

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by Teyandee · Jul 07, 2014 at 11:06 PM

I am not sure what I did but I accidentally fixed it I guess! I got done eating dinner, rebooted Unity... and well.. its working. Thanks to everybody helping me, again I really do appreciate it!

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue 1 Answer

OnTriggerEnter/Exit called unexpectedly 2 Answers

Access other collider without use of Trigger collider. 1 Answer

Can't get trigger to work 1 Answer

OnTriggerEnter not being called, have trigger, RB, and colliders set? 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