• 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 isKinematic = 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

32 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 avatar image

Related Questions

Multiple Cars not working 1 Answer

Collider not working... 0 Answers

Boxcollider 2D Destroyed 2 Answers

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

Need help with game points and trigger 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges