hello, i have a scene with a player prefab that contains a main capsule with various scripts, an orthographic camera that is a child of that capsule, and a (-n obsolete) spawnpoint.
i'm using this bit of code to draw a Gizmo on the screen and calculating where the world coordinates are, and it seems off:
var cam : Camera;
var Val : int = 8;
function OnDrawGizmosSelected()
{
var p : Vector3 = cam.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, Val));
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(p,1);
}
function Update()
{
print(Input.mousePosition);
}
and it looks perfect in the game view, but in the scene view.... it's a little off, and if i were to put a transform.position = ScreenToWorldPoint (my main goal), it would be wrong,
so is there a way to make the screen coords the ACTUAL world coords so that if i put my mouse on an object say at game(world) 0,5,0 in the game mode, then in the scene view, it would move the Gizmo to the scene(world) 0,5,0?
The thing is, if you define a point on the screen, in 3D, it defines a line that goes from the camera, through that screen point, and runs out to infinity.
As you’re finding, it doesn’t tell you where to stop. (‘depth’ coordinate)
I haven’t had any experience with this yet, but what I have read about people doing is using a RayCast from the camera, through the Screen Point, and read the point where it hits something in your scene as the point you want.