#Help with tagging

1 messages · Page 1 of 1 (latest)

karmic shoal
#

https://paste.myst.rs/s8zl1sbx
I am making a 2d shooter game and I am trying to make it so my bullets only hit and disappear a object with the enemy tag. How can I make it so only objects with the enemy tag get hit? As it is now the bullets hit and disappear the player and other objects.

sonic shuttle
#

to compare tags you would use something like:

        {
            enemy.TakeDamage(damage);
            Destroy(gameObject);
        }

In your previous post however, another user pointed out that this is not really a solution for your current problem. You should instead be trying to remove collisions between objects. This is not done using tags.

#

as you instantiate your bullet you could do something like:
Physics2D.IgnoreCollision(firedShot.GetComponent<Collider2D>(), playerCollider);

#

which would ensure the bullets shot don't collide with your player

dreamy dirge
#

The best way to globally prevent collisions is setting different layers on different objects, and then using the Layer Collision Matrix in the project settings to select which layers can collide with which.

#

Tags are not meant to filter out collisions.
And frankly, there also are better ways to determine, which object you hit - since usually, there would be a component attached to relevant objects, which you would need to access anyway.