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 rick-grendel · Oct 16, 2014 at 04:07 PM · javascriptcollidertriggerboolean

Boolean wont acitvate if the enemy enters a trigger

Hello I have a Script this script is very simple i have a enemy and i have a boxcollider called waypoint. When the AI (enemy) enters the trigger a boolean should be true. But its not happening. the AI has the tag Enemy on it. So.... here is my script

 #pragma strict
 
 var enter : boolean = false;
 var Enemy : GameObject;
 
 function OnTriggerEnter (poppen : Collider) {
 
      if(poppen.collider.tag == Enemy.tag)
      enter = true;
 }
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 pauloapsantos96 · Oct 16, 2014 at 04:22 PM 0
Share

Does the AI have a collider attached? If so, is the variable Enemy initialised

avatar image rick-grendel · Oct 16, 2014 at 04:24 PM 0
Share

@pauloapsantos96 yes it have a boxcollider on it and the tag is a standard tag

avatar image N1warhead · Oct 16, 2014 at 04:31 PM 0
Share

I don't know Unityscript that well anymore but it looks correct, but colliders aren't the only thing you need.

Add a Rigidbody to him and put is$$anonymous$$inematic = true

This may help also with formatting as I can't tell to well with Unityscript but in C# the way you detect tags is this (could be the same in US)

 if(poppen.gameObject.tag == "NameOfTag");


So anything with the tag of NameOfTag will react with it.

avatar image rick-grendel · Oct 16, 2014 at 04:36 PM 0
Share

@N1warhead Tank you so much i am thinking of this the whole day :)

1 Reply

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

Answer by jtsmith1287 · Oct 16, 2014 at 05:07 PM

When using any kind of collider, be it a mesh collider, box collider, capsule, etc, one of the colliding objects must also have a RigidBody component. If you need collision but don't want physics, simply check the IsKinematic box. I'm just making an assumption here, so hopefully this is the problem.

Your code looks fine, and you don't need to hardcode "NameOfTag". That is bad. If Enemy.tag is "NameOfTag", then if(poppen.collider.tag == Enemy.tag) will return True if poppen.collider.tag is also "NameOfTag". So, make sure the tags are set, and that the gameobjects have rigid body components. Good luck!

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 rick-grendel · Oct 16, 2014 at 05:10 PM 0
Share

I have already the answer in the comments but you are the only one who give the answer

avatar image jtsmith1287 · Oct 16, 2014 at 05:12 PM 0
Share

Oh I didn't actually see that they also mentioned the rigid body issue in the comment. I just skimmed and saw the tag hardcoding. :P

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

31 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Gesture Sequences in javascript 1 Answer

Collider not working... 0 Answers

OnTriggerEnter Does Not Recognize Collider That Is Moved By iTween 0 Answers

Need help with game points 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