- Home /
Is their a way to change boxcollider2d's method of detection?
I notice that the way unity handles collision detection in 2d is by checking if the collider's overlapped then moving them to a point that they can no longer overlap. Picture below show's what I'm trying to say. However this type of behavior is not gonna work well when at the middle of a land-able object your player could take damage.
For example in my case I had a projectile that the player can land on. The tip of this projectile can cause damage to the player. But because of they way collision works in unity the player would still take damage.
Answer by UnityNoob123 · Oct 22, 2017 at 04:02 AM
What you could do is create an empty gameobject and make it a child of the platform gameobject, and there make a circle collider 2d of where you want the player to take damage. Then change the tag of that gameobject to something like "DamageCollider", while on the parent gameobject leaving the box collider tag "Default". Then on your player you could do something like:
void OnColliderEnter2D (Collider2D col) {
if (col.gameObject.tag == "DamageCollider") {
//do damage
}
}
Or if you have a script on the platform gameobject child, do something like:
void OnColliderEnter2D (Collider2D col) {
col.GetComponent<playerController> ().takeDamage;
}
I hope this answered your question, there is only one way to change the behavior of the collider system which would be making it a trigger, which will just detect the collision and have your player fall through it. If you have any follow up questions or need additional help just @me, and I hope understood your problem correctly.