# Manual orbit motion jerks at a certain point

So I've been trying to make a simple sphere-orbiting-another-sphere test. The smaller sphere is supposed to circle the bigger one based on the mouse location.

Here is my code:

    //script is assigned to the smaller sphere
screenpos = Camera.main.ScreenToWorldPoint (Input.mousePosition);

if (screenpos.x <= centerball.x + 2f && screenpos.x >= centerball.x - 2f) //orbit radius is 2
{
xpos = screenpos.x;
ypos = (Mathf.Sqrt(4f-Mathf.Pow((xpos - centerball.x),2)))+centerball.y;
//generated value of y from an equation
//equation of circle -> y = sqrt[(r^2)-(x-h)^2]+k

if(screenpos.y <= centerball.y)
{
ypos = -(Mathf.Sqrt(4f-Mathf.Pow((xpos - centerball.x),2)))+ centerball.y;
//equation of circle when square root has negative sign
}

transform.position = new Vector3(xpos ,ypos,0);


The code is quite straightforward. Basic math equations and all. And it works all fine except for when xpos gets close to the values of "centerball.x ± 2f ".

It stops moving as I approach the value and then jerks forward, skipping an entire set of values of ypos in between.

So I checked my formula and it is absolutely correct. There is no value of xpos where ypos cannot be obtained (no negative squares).

I did a little thinking and came to the possible conclusion that the value of screenpos was rounded off too much (debug.log showed only 1 decimal place), causing the value of ypos to lose accuracy and jump as the value of xpos approached the previously mentioned bounds. If this is the cause, is there a way to record screenposition more accurately or any other way to get around this problem?

And if this is NOT the cause, can someone please explain what is going on here?

screenpos = Camera.main.ScreenToWorldPoint (Input.mousePosition);