# How can I shoot a projectile into mouse position?

Hello. I run into a problem becouse i dont know how to shoot bullet at mouse direction. Thats my code so far:`

``````void Update()
{
if (Input.GetButtonDown("Fire1"))
{
float mouseX;
float mouseY;
mouseX = Input.mousePosition.x;
int intMouseX = (int)mouseX;
mouseY = Input.mousePosition.y;
int intMouseY = (int)mouseY;

Vector2 FinalMousePos;
FinalMousePos.x = intMouseX;
FinalMousePos.y = intMouseY;

Instantiate(bullet, Gracz1.transform.position, Gracz1.transform.rotation);
bullet.GetComponent<Rigidbody2D>().velocity = FinalMousePos * Bulletspeed;
}

}
``````

Thanks for help.

Ok i completely revamped my entire script. Now it looks like this:

``````if (Input.GetButtonDown("Fire1"))
{
clickPos = Vector3.one;
Vector3 punktA = new Vector3(1, 2, 0);
Vector3 punktB = new Vector3(2, 1, 0);
Vector3 punktC = new Vector3(3, 3, 0);
Plane plane = new Plane(punktA, punktB, punktC);
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
float DistanceToPlane;
if (plane.Raycast(ray, out DistanceToPlane))
{
clickPos = ray.GetPoint(DistanceToPlane);
}
Vector3 finalClickPos = new Vector3(clickPos.x, clickPos.y, 1);
Instantiate(bullet, transform.position, Quaternion.LookRotation(finalClickPos));

}
``````

It works ok but when i instentiate bullet it gets rotated to the opposite corner (for instance when i click in the upper right my bullet gets rotated towards upper left corner) How can i fix this?
@RustyCrow

Try →

``````var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
bullet.GetComponent<Rigidbody2D>().velocity = (Character.position - mousePosition).normalized * bulletSpeed
``````

Edit :
Things in Arrow brakets dosent show up. so i added it in as code. Also added how to get mouse world position since OP did not do it correctly.