- Home /
How To: One collider for detection; one for collision.
This is a general question so there really isn't any code to add.
I have a number of objects that travel along a terrain. These are primitive cylinders that are my game objects/tokens/units. I need to have each unit have both a combat radius/distance and a detection radius/distance. These are all NavMeshAgents.
Combat distance/radius: This is equal to touch...if it touches an enemy, there is combat (I can code this with a collider, no problem).
Detection distance/radius: This goes out a ways...if an enemy moves within a certain distance of a friendly unit then it "appears" visible to the friendly unit (again, no problem, I can code this with a collider).
HERE's the PROBLEM! I don't know how to add them BOTH to the same friendly unit. I've been doing some research on how to add two colliders to the same object that each has different functions. I'm trying different combinations but I haven't found anything that works yet. Do I add another object to the main object (as in a parent/child) or do I add a second collider to the same object?
I can't really find anything on point (you don't need to do my research for me) but I need a starting point where I might find a solution to my problem.
Thanks in advance.
Answer by ollie_payne · Sep 04, 2017 at 05:07 PM
You could attach a child object to the neccessary object, zero the position, and add the second collider onto that, with its own neccessary script etc. This is really the only way about this unless you want to create a script which compares distances between relative objects using Vector3.Distance(), or, Vector2.Distance() to complete the actions you require. Hope this helps.
Yes, it helps a lot. It gives me a good direction to go in and many things I can eli$$anonymous$$ate.
I've just (earlier today) added my first child object to another in the hopes that this would be a solution but I've got some bugs to work out.
I appreciate that you took the time to help me and I'll work on this for a bit.
Works like a charm.
I couldn't figure out how to set up the child collider at first but once I set up the child collider layer to ignore raycasts it worked perfectly.
Wow. I'm really excited by this. It takes me a large step forward in my project.
Thank you kindly for your help.