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?
#Collider Issue with Hit Recognition
1 messages · Page 1 of 1 (latest)
I dont know. Can I put different Colliders of the same object on different layers?
Yeah but they need to be on different objects
Like children
Because one gameobject has only 1 layer
But its perfectly fine to split into children for that
So just make an empty object on the Enemy and put the collider on there?
Yeah
Do I have to refer to that radius collider in a different way when its not on the main object anymore?
Not sure how you are referring to it currently
But you can just have a serialized field that you drag it to
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
I believe OnTriggerEnter etc. get called on the object that has the rigidbody
So the script would have to be on the same object that has the RB
Alright, shouldnt be a problem
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?
Sure
Just heard, having everything on public is poor coding