i want to instantiate a GameObject in mouse position and i can use camera.ScreenToWorldPoint or ScreenPointToRay methods for finding the world position. i can not use raycasting in my situation. so i need a method to find what is the world position of mouse in (for example 100m away) from the camera position. because camera view is perspective and the view is a cone some calculations are needed. as i know i should take the difference of mouse position from center, into account and use the fieldOfView value to find the angle of the line that i should go on to find the position but i can not produce working code. my code is like this inside Update() function.
if (Input.GetMouseButtonDown(0))
{
Vector3 a = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x,Input.mousePosition.y,0));
a.z = 0;
print(a.z.ToString());
Instantiate (fairy,a,Quaternion.identity);
}
the camera is placed at (0,0,-10) and i want to create fairies at z position of 0.
i have a related question as a featured question too.