Launch object at mouse position

I want to be able to click somewhere on screen, and have an object be thrown at that exact position.

I’m checking the mouse position on click like so:

if (Input.GetMouseButtonDown(0)) {
    targetLocation = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}

Then launching the object like so:

rigidBody.AddForce(targetLocation - (Vector2)transform.position, ForceMode2D.Impulse);

It’s thrown in the direction of where I’m pointing, but falls short way before it reaches the mouse position. I want the object to always pass through the mouse position.

As long as gravity is involved, it will pull the object down off the straight-line course.

If you want a straight-line laser course, turn gravity off or turn it to zero, either globally or for your bullet.

If you want gravity, then the classic physics dynamics equations (google) give you calculations for how much “up” you need to impart to the object to ultimately pass through a given point, given constant gravity.

You can google for words like trajectory or ballistics in a Unity3D context and there are plenty of interesting tutorials to help you solve this common problem.

Note that in games such as Angry Birds, the act of actually “aiming high enough” is the actual game that the human is tasked with doing properly.