- Home /
problem with collisions with tag
I have made a point cube prefab in my splitscreen FPS that the player drops when they die, when the player walks over it the cube destroys itself using a collision based scritp that only triggers if the colliding object's tag is "Player" but for some reason the cubes destroy itself when hit buy a player's bullet even though the bullet's tag is not "Player" but I created a custom one called "bullet"
Anyway I can fix this?
tip: It's impossible to reason about your code without ever seeing it.
Answer by Pigenator · Jul 01, 2017 at 07:45 AM
Please provide us with the script you use. The information you have given isn't enough to pinpoint the problem.
Answer by Vicarian · Jul 01, 2017 at 07:47 AM
Collision is determined by the layer an object is on, not its tag. If bullet is placed in a separate layer, you can disable collision between bullets and the cube by using the Collision matrix in Edit > Project Settings > Physics. The intersection of a row and a column represent a pair of layers that can collide with each other. Simply uncheck the box at the intersection of the cube's layer and the bullet layer.
I don't think that was what he/she meant to do. I think it's like this:OnTriggerEnter(Collider other){ if(other.GameObject.tag == "Player"){ Destroy(gameObject) } }
Answer by EliteHedgehog56 · Jul 01, 2017 at 11:01 AM
oh yeah forgot about my script
here's the script im using for the cube
function OnCollisionEnter(collision: Collision) {
if (collision.gameObject.tag == "player");
Destroy (gameObject);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612125254im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycast that ignores object with certain tags? 2 Answers
Creating a dialogue with Physics.OverlapSphere 0 Answers
working with tags 2 Answers
Best way to list multiple tags... 2 Answers