x


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.

more ▼

asked Sep 11 at 08:44 AM

benedikte\'s gravatar image

benedikte
31 1 1 5

(comments are locked)
10|3000 characters needed characters left
 moderation talk

1 answer:

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);
}
more ▼

answered Sep 13 at 11:28 PM

JTBentley\'s gravatar image

JTBentley
487 3 4 16

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.

Sep 17 at 10:26 AM benedikte

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.)

Jan 05 at 04:35 PM Smorpheus
(comments are locked)
10|3000 characters needed characters left
 moderation talk
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1650
x325
x239
x99

Asked: Sep 11 at 08:44 AM

Seen: 1030 times

Last Updated: Sep 11 at 10:23 AM

powered by Qato - Enterprise Q&A