- Home /
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
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.
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>());
Your answer
Follow this Question
Related Questions
Safe area from enemies 1 Answer
Detect collision/trigger between two body without rigidbody? 3 Answers
Trigger script does not work. 1 Answer
How come the Trigger teleports when its not supposed to! 1 Answer
Trigger not detecting tag 1 Answer