Input.mousePosition to World converts to Camera's position, No matter where I click

I want the script to draw a line between two positions, the position of the object the script is on and the position of where I clicked the mouse, without Raycasting

Vector3 spawnPos = transform.position;
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Debug.DrawLine(spawnPos, mousePos,;

Draws the line in the picture above.

You are using Camera.main.ScreenToWorldPoint() wrong. You need to calculate correct z value for the Vector3 parameter. Because you are passing 0f for z it calculates world position 0f units away from camera, which, because of math reasons, always happens to be position of camera.

It’s pretty easy to calculate correct z value, here’s the example:

Camera.main.ScreenToWorldPoint(new Vector3(
    -Camera.main.transform.position.z + zPositionOfThePlane));