Tryna get the position of the mouse in world space

I’m trying to spawn an object in a certain position (in a 2d game) where the position is where the player clicks on the screen with the mouse. So I’m using

spawnPos = Camera.main.ViewportToWorldPoint(Input.mousePosition);

to get the point (I think that’s where I’m going wrong) and then setting it as a clone’s pos with

clone.transform.position = spawnPos;

I’ve also tried using Camera.screenToWorldPoint, but that didn’t seem to do it in this case either. Anyone know a good solution to this? Appreciated! :slight_smile:

try this isnstead

spawnPos = Camera.main.ScreenToWorldPoint(Input.mousePosition)