My game is a 2D topdown. The only collider on the scene is the on the player. The camera we’re using is inside the player.
.
Using ScreenToWorldPoint becomes more inaccurate the farther away from the player the mouse is, and using RayCasts has given me absolutely nothing.
.
I’ve copied and pasted a million scripts and none of them work. Some place the object directly at (0,0), and some don’t even place at all. Raycasts don’t even know what to do because I obviously can’t make my entire background a collider if players are moving through it.
.
This kinda works:
Vector3 mouseposition = Input.mousePosition;
mouseposition.z = 10;
Vector3 pos = (cam.ScreenToWorldPoint(mouseposition) - transform.position).normalized;
GameObject b = Instantiate(box , cam.ScreenToWorldPoint(mouseposition), Quaternion.identity);
But it “works” because it places it where your mouse is, but that is waaaay above the player. So set the Z to 0 immediately after placing so it’s on the player’s level? Well now it’s inaccurate and doesn’t place where you clicked at all!