How Do I Increase/Decrease Velocity Based on Distance Between Objects

My code launches the player based on the angle between an object and the cursor. Is there any way to also calculate the distance between the them and launch it proportionate to that distance?

‘’’

public class FirstController : MonoBehaviour
{
    public GameObject Aiming;
    public GameObject Player;
    public float launchForce;
    public float jumps = 1f;

    void OnCollisionStay2D(Collision2D col)
    {
        if (col.gameObject.name == "Square")
        {
            jumps = 1f;
        }
    }

    void Update()
    {
        Vector2 lastPosition = Aiming.transform.position;
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 direction = mousePosition - lastPosition;

        if (Input.GetMouseButtonDown(0))
        {
            Aiming.GetComponent<Transform>().position = mousePosition;
        }
        
        if (jumps > 0)
        {
            if (Input.GetMouseButtonUp(0))
            {
                transform.right = -direction;
                Shoot();
                jumps = jumps - 1;
            }
        }

    }

    void Shoot()
    {
        GetComponent<Rigidbody2D>().velocity = (transform.right * launchForce);
    }
 }

Probably best to start with an Angry Birds tutorial.

As I wrote to you in your other thread, get the distance with Vector3.Distance();

Now develop an expression (function) to map distance to your desired launch velocity.

If ANY of that sounds mysterious, hurry hurry hurry to an Angry Birds tutorial. Nobody’s gonna retype it for you here and in any case it will be a LOT more than just code.

Regarding the typing mistakes in your other thread:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.