• 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 laurienash · Sep 24, 2013 at 09:08 PM · collisiontriggertag

Ignore collision on tag not working

HELP...

When my player hits a collider - a set of game objects are instantiated. Before he reaches it - an NPC walks through this collider, and I don't want him to trigger these instantiations.

I am using this script to ignore the collisions (below): the first time I used it, it worked and the scene wasn't instantiated. Now, it isn't working any more, and I have not made any changes to this part of the game! This collider has been acting strangely for the past few days, sometimes only instantiating some objects when the NPC walks through, and sometimes all of them. I really can't understand what's going on!

 var npc : GameObject;
 
 function Start () { 
 
  var ball = GameObject.FindGameObjectWithTag("Ball");
 
   Physics.IgnoreCollision(npc.collider, collider);
    
    Physics.IgnoreCollision(ball.collider, collider); 
 
        }

I originally used OnTriggerEnter - which worked a few days ago, but now doesn't at all (and looking around online it seemed Start was a better idea. This is the script I'm using to instantiate the objects, in case that helps (the commented out part was where I tried to get the collider to ignore the NPC collision within this script, but that doesn't work.

 var plane : GameObject;
 var bird : GameObject;
 var flockControllerGameObject : FlockController;
 var planeSounds : AudioClip;
 //var npc : GameObject;
 
 
 function OnTriggerEnter (other : Collider) { 
  
   //var ball = GameObject.FindGameObjectWithTag("Ball");
 
   //Physics.IgnoreCollision(npc.collider, collider); 
  // Physics.IgnoreCollision(ball.collider, collider); 
 
  if(other.gameObject.tag == "Carl")
 
 
     bird.SetActive (true);
     flockControllerGameObject.ReviveBirds();
     plane.SetActive (true);
     plane.transform.position = Vector3(590.788,125.2536,224.8894);
     planeSounds = plane.audio.clip;
     audio.clip = null;
     plane.audio.clip = planeSounds;
     plane.audio.Play();


Does anyone know whether its my computer that's playing up - or is there something wrong with the script? Thanks in advance, Laurien

Comment
Add comment
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

2 Replies

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

Answer by Lukamyte · Sep 25, 2013 at 10:55 AM

I usually use something like:

 if(other.tag == "tag"){
     //do something
 }

In my current project I use this quite a lot. But about the if statement, I would recommend using other.tag instead of other.gameObject.tag.

Comment
Add comment · Show 1 · 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 laurienash · Sep 25, 2013 at 11:59 AM 0
Share

THAN$$anonymous$$S that seems to have worked :)

avatar image
1

Answer by Esteban-Gallardo · Jul 26, 2014 at 11:14 AM

Beware of CharacterController, which also triggers a collision. So, you have to ignore two colliders, BoxCollider/SphereCollider and CharacterController. My code:

     // IGNORE COLLISION WITH PLAYER
     Physics.IgnoreCollision(Character.GetComponent<SphereCollider>(), WorldEngine.Instance.MyGameBoard.MyPlayer.Character.GetComponent<BoxCollider>());
     Physics.IgnoreCollision(Character.GetComponent<SphereCollider>(), WorldEngine.Instance.MyGameBoard.MyPlayer.Character.GetComponent<CharacterController>());
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.

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

16 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

Related Questions

Safe area from enemies 1 Answer

Funny error. collision just hit 12 times 1 Answer

OnCollision Script... 2 Answers

Trigger script does not work. 1 Answer

How to fix the position of a character when grabbing a rope? 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