#Collider Issue with Hit Recognition

1 messages · Page 1 of 1 (latest)

minor rapids
#

I have the following issue. I use the Unity Physics Engine to check if I hit the enemy. But I also use a Circle Collider 2D to give my Enemies a visual range of when to respond to the player. Now when my Bullets hit this specific Circle, they dissapear, because it counts as "hitting the enemy". Is there a way to specify which Collider of the enemy is important to my bullets?

true falcon
#

Does that help?

minor rapids
#

I dont know. Can I put different Colliders of the same object on different layers?

true falcon
#

Like children

#

Because one gameobject has only 1 layer

minor rapids
#

Ohh I see

#

That could work

#

good call

true falcon
#

But its perfectly fine to split into children for that

minor rapids
#

So just make an empty object on the Enemy and put the collider on there?

true falcon
#

Yeah

minor rapids
#

Do I have to refer to that radius collider in a different way when its not on the main object anymore?

true falcon
#

Not sure how you are referring to it currently

#

But you can just have a serialized field that you drag it to

minor rapids
#

Alrighty, I give it a try

#

So I have a component called "Vision" now which is the children with the Circle Collider

#

Does that one need a script now for OnTriggerEnter2D or can I do that in my main script?

#

I just used to do this:

   {
       if (other.tag == "Player") alert = true;
   }

   private void OnTriggerExit2D(Collider2D collision)
   {
       if (collision.tag == "Player") alert = false;
   }```
In my main script, when the collider was on the enemy
true falcon
#

So the script would have to be on the same object that has the RB

minor rapids
#

Alright, shouldnt be a problem

true falcon
#

I barely do 2D so I'm not sure if it works like in 3D

#

Yeah should work as it is

minor rapids
#

Yeah 2D is easier for a University Project

#

Soo I use a bool called alert, that turns true, when someone is in the area. I probably need that to be public, so the enemy can use that info?

minor rapids
#

Just heard, having everything on public is poor coding