- Home /
Question by
Post-SpammeR · Jul 04, 2015 at 12:39 PM ·
objectscreencoordinatesto
Problem with Camera.ScreenToWorldPoint
I am trying to get screen coordinates for a 3D cube. I am using Camera.ScreenToWorldPoint as I don't know any other way to get the screen cords of 3D object in space.
my code:
#pragma strict
var cubePosition : Vector3;
var cam : Camera;
function Update ()
{
if(Input.GetMouseButtonUp(0))
{
cubePosition = cam.ScreenToWorldPoint(this.transform.position);
//cubePosition.y = Screen.height - (cubePosition.y + 1);
Debug.Log("this.transform.position: "+this.transform.position);
Debug.Log("cubePosition: "+cubePosition);
Debug.Log("Input.mousePosition: "+Input.mousePosition);
}
}
The script is attached to the cube.
The cube has rigid body with gravity
cubePosition always returns the same vector(0,1,-10) even if I change the position of the cube.
If I reverse the y coordinate then it always return (0,604,-10)
If I click the cube the mouse position is (328,243), I should get this coordinate from my cubePosition if done correctly, right? Well at least that's what I am trying to do.
Maybe its just some stupid little problem that I am not seeing, but I wasted way to much time on this. So I am asking for help or alternative to solve this.
Comment