Is it possible to know the angle of collider2D border in touch place with RigidBody2D?
And if yes, how to do it?
Answer by MelvMay · Feb 27, 2017 at 08:37 AM
You can calculate an angle from any vector using:
var angle = Mathf.Atan2(y, x);
In your example, you can either use the collision normal (points away from the surface) or use the collision tangent (points along the surface). The collision normal is provided by the OnCollisionEnter/Stay callbacks or in 5.6 you can use GetContacts to retrieve the contact point(s) that contain the collision normal.
When you have the Vector2(x,y) collision normal you can create a tangent vector in either direction along the edge above using Vector2(-y,x) and Vector2(y,-x). These tangents would typically define the motion along the surface in your image.
You can use the tangent to define the angle from the horiztonal. You could also use the collision normal as it's also 90-deg from the collision tangent. Use these vectors to create an angle.
Hope this helps.
Your answer
Follow this Question
Related Questions
All colliders not longer working 0 Answers
No overload for method. (Question) 0 Answers
Tilemap Collider not Colliding 0 Answers
2D Colliders don't actually touch, causing problems 0 Answers