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
0
Question by tokyomage · Jun 16, 2014 at 07:23 PM · javascripttrigger

On Trigger Enter Not Executing?

Edit Thanks to the user KillerStarBunny I was able to figure out my problem, I just needed to add a rigid body to my "lightCollider" object and I was good to go. Thanks.

Hello, I'm having an issue involving the "OnTriggerEnter" command. I have this code:

 function OnTriggerEnter(collider : Collider)
 {
     if(collider.tag == "lightCollider")
     {
     
     isAlerted = true;
 
     }   
 }

This code is inside of a script attached to an object with a capsule collider with "IsTrigger" set to false. The tag "lightCollider" is found on an object that has a capsule collider with "IsTrigger" set to true.

My problem is that when the lightCollider object moves into the collider for the object holding the script, isAlerted does not change from false to true.

If this might help, here is the entire script including the snippet mentioned above:

 var target : Transform;
 var moveSpeed = 3;
 var rotationSpeed = 3;
 var myTransform : Transform;
 
 var animation_crouchedIdle : String;
 var animation_standUp : String;
 var animation_moving : String;
 var animation_attacking : String;
 
 var you : Transform;
 var thePlayer : Transform;
 var dist : float = 10.0;
 
  var isAlerted : boolean = false;
 
 
 function Awake()
 {
     myTransform = transform;
 }
 
 function Start()
 {
     
     target = GameObject.FindWithTag("Player").transform;
     
     for (var state : AnimationState in animation) {
     state.speed = 0.75;
 } 
 
 }
 
 function OnTriggerEnter(collider : Collider)
 {
     if(collider.tag == "lightCollider")
     {
     
     isAlerted = true;
 
     }
      
 }
 
 function Update()
 {
 
 if (isAlerted == true){
 
     GetComponent(NavMeshAgent).destination = target.position;
     transform.LookAt(Vector3(target.position.x, transform.position.y, target.position.z));
            
       var distanceToDestroy = Vector3.Distance(thePlayer.position,you.position);
 
 
                       if (dist > distanceToDestroy){
                 animation.CrossFade(animation_attacking);
         
         }
         
         
             if (dist < distanceToDestroy){
 
                 animation.CrossFade(animation_moving);
         }
 }
 
 if (isAlerted == false){
         
 animation.CrossFade(animation_crouchedIdle);
 
 }
 
 }

Please post actual answers and not just links to a webpage that might hold the answer. Thank you.

Comment
Add comment · Show 4
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 Ben-Stoneman ♦♦ · Jun 16, 2014 at 07:38 PM 0
Share

I guess the first question is does the object definitely have the tag "lightCollider"?

Also, could you comment on how you are testing the Trigger as I was unable to get it to trigger when moving the object with the script into the "lightCollider" via the scene view. (using 4.5.0f6).

avatar image tanoshimi · Jun 16, 2014 at 07:46 PM 0
Share

As with every question on this site about triggers apparently not firing, first thing to confirm is that you do have a rigid body attached to the object?

avatar image tokyomage · Jun 17, 2014 at 02:38 AM 0
Share

It does have the tag lightCollider. @Ben Stoneman that is the same problem I am having, it just isn't triggering. That's what I'm asking. Also, I do not have a rigid body attached to the object.

avatar image KillerStarBunny · Jun 17, 2014 at 02:42 AM 0
Share

Add a rigidbody

1 Reply

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

Answer by tokyomage · Jun 17, 2014 at 03:21 AM

I figured it out! I needed to add a rigid body to my "lightCollider" object in order for it to execute the trigger object, thank you so much @KillerStarBunny .

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Showing text near object 1 Answer

How do I loop my light animation is javascript? 1 Answer

How do I trigger events using color using JavaScript? 1 Answer

Check collision of childs Trigger in Parents script [JS] 1 Answer

On Click, destroy object and any colliding object with the same tag. 6 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