How to change the angle of an object in accordance with the surface?

I have an object with circle collider 2d, and an uneven surface with polygon collider 2d.
Now angle up. And it is necessary that the angle of the object was, depending on what angle from the surface.
April 3rd 20 at 17:35
1 answer
April 3rd 20 at 17:37
You need to get the shortest distance from the center of the Collider to a point on the surface all the way to the curve and just create an array of object rotation angles based on location relative to the path surface.

PS: Point of contact - it is better not to take it, because if the object jumps, falls with the slope it will be easier to swing.
In contact I get a surface normal vector tobish. How can I convert in the right corner?
void OnCollisionEnter2D(Collision2D col){
 foreach (ContactPoint2D contact in col.contacts)
- Faye_Brakus commented on April 3rd 20 at 17:40
@Faye_Brakus, to build the equation of the line passing through two points.
Through the center of the Collider and the point of contact.
And then calculate the angle relative to the horizon. - Raphael.Bergstr commented on April 3rd 20 at 17:43
transform.eulerAngles = new Vector3(0, 0, Mathf.Atan2(-contact.normal.y-contact.normal.x) * 180 / Mathf.PI);

If anyone is need. - Faye_Brakus commented on April 3rd 20 at 17:46

Find more questions by tags Unity Game Engine