[Solved]InverseTransformPoin problem

Hi all, well I’m trying to implement part of the code of the ObjectLabel example from unifycommunit, here it is:

   if (clampToScreen) {
        var relativePosition =Camera.main.transform.InverseTransformPoint(target.transform.position);
        
	    relativePosition.z = Mathf.Max(relativePosition.z, 1.0);
        thisTransform.position = Camera.main.WorldToViewportPoint(Camera.main.transform.TransformPoint(relativePosition + offset));
		//thisTransform.position = Camera.main.WorldToViewportPoint(target.transform.position + offset);
		
        thisTransform.position = Vector3(Mathf.Clamp(thisTransform.position.x, clampBorderSize, 1.0-clampBorderSize), Mathf.Clamp(thisTransform.position.y, clampBorderSize, 1.0-clampBorderSize), thisTransform.position.z);
    }
	}
	
    else {
	     thisTransform.position =Camera.main.WorldToViewportPoint(target.transform.position + offset);
           }

The problem seems to be in "clampToScreen" if i do a Debug.Log(relativePosition) right after " var relativePosition =Camera.main.transform.InverseTransformPoint(target.transform.localPosition);
" the result is: (0.0,0.0,0.0) 

The position of the Camera: (48242,9, 1035,4, 52354,5) and the target position: (47409,3, 88,7, 52738,0)

Any clue what could be the problem? 

Thanks in advance.

With the input you posted, you should not be getting the zero vector. I would add some debug output immediately prior to the call to InverseTransformPoint() and print out both Camera.main.transform.position and target.transform.position to see if they’re the same. (It may be that the target object is assigned incorrectly or that your input is otherwise incorrect.)

Thanks for your reply, I solved the problem, the camera scale was (0,0,0), so that’s why I was getting (0.0,0.0,0.0) as result.