Shooting a bullet at mouse position.

So i have been following a guide on how to make a rougelike game, and everything was until i came to the part where i had to fire a bullet. In guide he could fire the bullet in whatever direction he wants, but when i try, it only wants to fire in the topright quarter of the screen.

Here is my code:

Any help would be very appreciated.

Y-Hello there,

If your Camera is set to Perspective you will need to use

Vector2 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane));

as you can see we are specifying that the Z “depth” of our mouse position to be the near clip of the camera, that is because the “Camera.main.ScreenToWorldPoint()” needs to know at which depth it should calculate the values.

Instead if your Camera is set to Orthographic you just need to use:

Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

because there’s no Z.

Hope this helps :slight_smile:

Thank you so much :smile:

Np :wink: