Hi all,
I’m currently in the depths of our first unity iPhone game, its all going well thanks to clear documentation and this amazing forum! Worked on other engines and have had terrible trouble getting reference material and information.
Anyway! I’m stuck on one point in particular. I have an object that when selected presents a menu, and one of the options on the menu is to move position. When move is selected the camera zooms out so you can see the entire map (from a top down perspective), you tap wherever on the map you want to move to and off the object goes. Any ideas on how to get this to work? I’ve tried a good few ideas but this problem seams beyond me, nothing I do gets the object to move to where I’ve tapped. The best I seam to get is the object moving relative to the iPhone’s screen, not relative to the actual map which is quite big.
ANY help is much appreciated as this has just stumped me. I’m hoping its just something silly I’m missing and just can’t see any more!
Many many thanks in advance! 
Seems like you’d want to:
-
Use the ScreenPointToRay function to take the touch position (2D) and turn it into a Ray, then Physics.Raycast() to cast a line through the world (3D).
-
Find the point (3D) where it hits the terrain that you want (by checking the results of that function)
-
Then command the object to move to that certain position in the world-space.
Hope this helps! Good luck!
Thanks 0turner0,
thats pretty much what i want and got going. I fixed my problem, the position the object moved too was always off and couldn’t figure out why. In the end switching orthographic to true for the main camera fixed the problem and gave me one to one positioning for the game object.
Thanks for the heads up though, now on to the next problem! GUI returning weird values!
Glad it helped - the orthographic thing makes sense in a way, since the ray would always stick straight out, and not be affected by the field of view…
There’s probably some calculations that could be done based on the screen position and FOV for the camera that would get you an angle to multiply the ray by, but if you’re happy with orthographic go for it!