It looks like there is garbage in your mousePosOld variable when you first detect a click (through if (Input.GetMouseButton(0))): it seems you use an uninitialized value for it (most likely (0, 0)) for the first click, or the value you got from the last time you had mouse-down.
Assuming you'll not get a mouse click event on the first frame, you could update ...
From what I understand the fact to compute your angle on Viewport space messes everything up due to origins. If you do your computation on Screen space everything will work just fine.
Update your code with this:
var p2 = Input.mousePosition + Vector3.forward * transform.position.z;
var p1 = Camera.main.WorldToScreenPoint(transform....
This is easier than you think!
// Get the vector toward the next waypoint from here.
Vector3 forward = TargetWaypointPos - transform.position;
// Get the local "up" vector pointing out of the planet to here.
Vector3 up = transform.position - SphereCenterPos;
// Form an orientation that points the z+ axis along "forward",
// and the y+ axis as close as ...
Input.GetAxis() returns the velocity of the axis in that frame. For example, getting the x-axis from a controller with a joystick will return the same thing as if you had moved your mouse to the right a certain amount. Input.GetAxis() will not tell you the overall movement of the mouse over multiple frames, or the position of the mouse on the screen.
To get ...
To get the local position, rotation you can decompose the local matrix of the child object. You can calculate the local matrix by multiplying the inverse global matrix of the parent with the global matrix of the child. Like this (example with glm)
Matrix4 invParentMatrix = glm::inverse(GetParent()->GetGlobalMatrix());
LocalChildMatrix = invParentMatrix ...
The reason you see the rapid back and forth movement as it tried to align itself to the player's axis is because of overshoot, as you probably guessed. I reconstructed what I believe you are trying to do using Vector3.MoveTowards instead. This function is useful because it does not overshoot. Unfortunately this code is untested so let me know if it works.
you need polar coordiates. you need to find the position in polar coordintaes(radius,teta) to unity basic cartesian coordinates(x,y)
you can move the object by changing the theta angle
this is my example code:
private void FixedUpdate()
foreach (var item in PolarElements)
float x = item.radius * Mathf.Cos(item.myAngle);