I have a 2D game with a slingshot mechanic, where the player clicks an object and drags it to aim where it will launch. However, it does not seem to be very smooth. If I move the mouse position very slightly it doesn’t change the aiming position until the mouse is a certain distance, then it will “snap” to the next x or y coordinate. I have tried lerping this, but that only gives the appearance of more precise aiming, because it smoothly transitions between the snapped positions, but does not actually allow for the mouse to settle in between snap points. So how would I make the mouse position be more precise? Here is the code I am using for the dragging function.
function OnMouseDrag()
{
var pos = Input.mousePosition;
pos.z = -Camera.main.transform.position.z;
pos = Camera.main.ScreenToWorldPoint(pos);
//Clamps launching object to a circle around the launch point
var newPos = pos + offset;
transform.position = startPos + Vector3.ClampMagnitude((newPos - startPos), radius);
//Clamps launching object from moving too far up or forward
transform.position.x = Mathf.Clamp(transform.position.x, -100, launchPivot.transform.position.x);
transform.position.y = Mathf.Clamp(transform.position.y, -100, launchPivot.transform.position.y);
}
}