I’m new to unity3d. I have seen this question has been asked in many places but I couldn’t figure out how to solve this problem. I have two objects with box collider 2d target and a ball with Circle Collider 2d. I want to detect the side of target box when ball hits the target.
simply my question is how to detect the side ball hits in the box(top,left,bottom or right). I could get the the position of the hitting object with following code but it’s useless.
This is going to be a little basic of me, but please forgive my ignorance, can anyone explain a bit as to why this works? or point me to a resource where I can read more about it. i’m a little confused.
The basic idea is that I grab the closest point on the collider box where the collision happened. I then get the calculate the min/max of x and y of this particular box. I then simply compare my point to these min/max values. It tells exactly what side of the box I am on.
Also Approximately is my own function that basically checks to see if the two values are within a threshold. It’s like Mathf.Approximately but I can control the epsilon.
Edit: You may have a problem with certain blocks returning size = 0,0,0 in some cases. If this happens then just go after size from the component