- Home /
How can I get the exact iphone screen touch position?
I've tried using the usual Camera.main.ScreentoWorldPoint(Input.GetTouch(0).position) but when I test it on my ios device the object(sprite) was really off from where I touch on the screen. I've set the screen to iphone landscape and whatever size I set the camera the result is still the same.
This code will only work if the camera is Orthographic and if there is a touch. Also you might check where you set the anchor for your sprite.
camera is orthographic, there is a touch and anchor is 0,0. This is 2D by the way. I'm still getting poor results for touch positions.
Input.touches[0].position is the position on the screen and that is exact position :D It seems to me you are trying to translate that into the world, but you lack info about it, what are you trying to achieve?
Ok here is what I've been trying, in the first state is a "Touch object event" storing the finger. a friend of $$anonymous$$e from term paper writing service wrote me this script that worked perfectly and i tried getting the same effect in playmaker with no luck:
using UnityEngine; using System.Collections;
public class PointAtFinger : $$anonymous$$onoBehaviour { Vector3 realWorldPos; Vector3 fingerPos; // Use this for initialization void Start () {
} // Update is called once per frame void Update () { #if UNITY_EDITOR fingerPos = Input.mousePosition; //for mouse #else fingerPos = Input.GetTouch(0).position; //for touch screen #endif Vector3 pos = fingerPos; pos.z = 8; realWorldPos = Camera.main.ScreenToWorldPoint(pos); realWorldPos.z=transform.position.z; transform.LookAt(realWorldPos,transform.up); //transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x,0,0); } }
Answer by unimechanic · Jul 11, 2014 at 04:04 PM
I tested and it works for me with a 2D sprite, but you need to add the z distance from the camera to be larger than nearClipPlane. Check the documentation:
http://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
Touch.position is a Vector2D, it's converted to Vector3D with z = 0, so you need to do something like this:
Camera.main.ScreenToWorldPoint(new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, 3))
Answer by upasnavig90 · Feb 12, 2018 at 11:20 AM
you can also check your canvas settings, try using UI Scale Mode as Constant pixel size with screen space render mode.
Answer by darkdoom973 · Jan 21 at 06:51 AM
There's a channel called Samyam, she has explained the exact same thing, Search Unity New Input System touch samyam, on youtube.
Your answer
Follow this Question
Related Questions
reaction game: measure time of touch exactly? 1 Answer
Unity Remote 3 and accessing multiple Input.touches? 3 Answers
Rotate on drag for IOS? 1 Answer
Unity 2D Mobile Game Drawing Mechanic 0 Answers
simple TOUCH of a 3D object in iOS 2 Answers