- Home /
find the tangent of a box / circle collider
I am trying to find the tangent of a box collier to add an explosion force, which isn't built in to unity 2D
It should find either the ray, or the point where the tangent hits.
Any ideas on how to do that? Thanks in advance.
What do you mean by "tangent to a box collider"? A box only has tangents at its edges...
Do you mean the angle of a colliding ray to the surface plane at the point of collision? Something else?
$$anonymous$$aybe the surface normal vector would help?
Sorry for me failing to express myself. I am trying to find (link to the referenced image)
the yellow points. The red point is the sort of viewpoint / originpoint or something
Well, you have 4 points, you should deter$$anonymous$$e which points are in the range of the red dot. there might be 2 or 3. If there is 2, then you have your points, if 3, the one with the biggest angle combined with the red dot gives you the answer.
to find which of them are in the range, you can put empty gameobjects just a little away from the corner, 0.1 for example and cast a ray towards the red dot and see if it hits the square object. that's what I would do.
But I'm sure someone else would give you simpler answer.
thanks koray, but i don`t know how to deter$$anonymous$$e the two points... I have tried raycasting before, but too many rays slow down the game extremly