The problem I’m running into, is that the ScreenToWorldPoint is giving the camera’s position in world units, not the mouse click’s input. This is verified with the Debug.Log, and by moving the camera inside of the editor with the coordinates changing accordingly.
ScreenToWorldPoint is a very descriptive method name. If you were expecting something completely different, then I have to say that this is going to be a very awkward discussion.
I don’t really understand what you’re trying to do. The prefab will be instantiated at a point relative to where the mouse cursor is located when you click on the LMB, which is what I believe you want to accomplish. What’s the problem?
I’m trying to get it to spawn the prefab where I am clicking in an absolute location (converted from the on-screen location) with the z transform forced to 0, rather than relative as you describe. No matter where I click on the screen, it always spawns exactly on the camera’s transform. I am clearly missing something here… in fact I suddenly get the feeling I’m using the entirely wrong function (this seems to be placing the screen’s center to the camera’s). Is that the case?
First, thanks for the response. I think I am not explaining my goal exactly. Basically I am trying to not tie the object placement to the camera, but rather a wprld coordinate computed by where the click was placed onscreen, then set the object’s absolute z position to 0 in the world. Thanks in advance for any further help!
ScreenToWorldPoint converts the exact position of a vector in screenspace coordinates to world space coordinates. If you have absolute world space coordinates in mind, then you would have to write your own algorithm for that based on the input that you have.
Change your neededZ to something else like 10/20. Like the others say. the z is the distance the object is spawned away from the camera and setting your neededZ to 0 means 0 units away from camera. Simple as that.
You’re trying to do several steps stuck together, and as such none of them are working. Separate out the steps logically, write code for each step, test, debug, and get it working.