# How to scale a sprite with distance to the mouse pointer?

Im trying to make a 2D golfing game where when you are lining up a shot an arrow points in the direction the ball is going to move in and scales up based on how far away the mouse is.

my code so far:

``````// Update is called once per frame
void Update()
{
transform.position = ball.transform.position;

Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
difference.Normalize();
float rotation_z = (Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg) + 180;
transform.rotation = Quaternion.Euler(0f, 0f, rotation_z);

transform.localScale = new Vector3(Mathf.Abs(Mathf.Clamp(Vector3.Distance(Input.mousePosition, transform.position) / 500, -25, 25)), Mathf.Abs(Mathf.Clamp(Vector3.Distance(Input.mousePosition, transform.position) / 500, -25, 25)), 0.1f);
print(Mathf.Abs(Vector3.Distance(Input.mousePosition, transform.position)) / 50);
}
``````

The issue with my code is that instead of scaling with distance it seems to just be scaling with the x position of the mouse.

void Update()
{
transform.position = ball.transform.position;
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float scale = Mathf.Min(difference.magnitude * 1, 25f); // replace 1 by the multiplier you want
transform.localScale = new Vector3(scale, scale, 0.1f);
difference.Normalize();
float rotation_z = (Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg) + 180;
transform.rotation = Quaternion.Euler(0f, 0f, rotation_z);
}