- Home /
How do I get ipad coordinate to match the ones in the editor?
I place an object in the unity iphone editor at (0,0,0). And I have a script that gives me the coordinates of a touch. When a run the app on the ipad a touch the place of my (0,0,0)-object then a get a debug message with a different coordinates then the (0,0,0).
How do I get the touch-coordinates to match the ones I set in the editor.
Hopes my questions makes sense and thank you for helping :)
(i'm working with an orthographic camera) I guess I'm asking for a way to control the relatioin between the cameras position a the screen space.
Answer by jtbentley · Sep 13, 2010 at 11:28 PM
I think the problem is you're getting the position of the collision itself (where the ray hits the collider). It sounds like what you want is the transform co-ords of the object you have hit.
So rather than hit.point, you'll want to find out what you hit, then get its transform. hit.collider.transform.position :)
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 200))
{
var objecthit:Transform = hit.transform as Transform;
print ("Object is positioned at :"+hit.collider.transform.position);
}
Thank you for the reply. It was a step in the right direction for me. I have to realise the difference between the "pixel-space" and the 3d space within unity.
I still don't get the link between the camera output I see in unity and the section of my scene I see on the ipad. How I can place or adjust the camera so I e.g. get my object centred on the ipad. I'm still so new at this that I don't even now what exactly I'm looking for.
Yeah, you should not be using precise coordinates - you should be testing for collision with your object. Using absolute numbers like that will end up screwing you if you have to change the slightest thing in the editor. You will have to go back and adjust all those coordinates manually. (I know this from mistakes I've made myself learning in the past 6 months.)