- Home /
Question by
abe90 · Aug 20, 2016 at 09:42 AM ·
gravity2d-physics
How to make 2d char run inside a circle
Hi all, I need to let a 2Dcharacter run inside a circle I have tryed a lot of ways but finally I did not find a solution.
My approach was to ray cast the ground and then to apply a force by considering the normal of the point hitten. something like:
Ray2D ray = new Ray2D (gameObject.transform.position, empty.transform.position);
RaycastHit2D hit;
Physics2D.Raycast (ray, out hit);
gameObject.GetComponent<Rigidbody2D>().AddForce(hit.normal* (-100));
(where the "empty" game object is placed under the feets of the character). I have correctly deactivated the gravity from the rigidbody2d but it does not work correcly and i do not understand why.
ps: the idea of the normals is driven by the fact that the circle is not a real circle but a set of short segments
circle.png
(18.2 kB)
Comment