- Home /
Other
How to get the tangent and normal of a collision?
In my game, one of my gameObjects casts a ray into a 2d space. If that ray were to hit another gameObject, I'd like to draw a line that is perpendicular to the tangent of the ray's hit point. So when the ray hits the other object, a tangent is formed at the point of contact, and then I'd like to use the linerenderer component to draw a line that is perpendicular to that tangent. I already know how to use the linerenderer to draw lines, but I don't know how to get the tangent and normal from a collision.
Answer by xxmariofer · Apr 03, 2019 at 06:59 PM
Raycasthit has a property called normal that should give you the normal, yoy only needed the tanget for getting the normal right?
Well the line that I want to draw has to be perpendicular to the tangent. I tried drawing a line with one point being the ray's hit point and the other being the ray.normal, and it did not look like it was perpendicular to the tangent.
which should be the normal of the hit point. if you want to be sure and you have the tangent the form the cross product of the tangent and the axis pointing into your screen.
I'd like to draw a line that is perpendicular to the tangent of the ray's hit point
are you sure you're using these words right ? the normal to a point on a surface is perpendicular to the surface. it's like a tree growing on the top of a hill. the tangents to a point on a surface (in 2D there are two, in 3D there are infinitely many) are parallel to the surface. they're like a tree that's laying down on the top of a hill.
by definition, the normal is perpendicular to all tangents.
so if you really want to draw a line perpendicular to the tangent, then what you want is the normal, and you don't need to get the tangent.
if what you want is actually the tangent, then in 2D the tangent is just the normal rotated by plus or $$anonymous$$us 90º.
// 2D tangents of a 2D normal. ie rotate +/- 90 degrees.
Vector2 N = the normal.
Vector2 T1 = new Vector2(-N.y, N.x);
Vector2 T2 = -T1;