Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by milkingcowboy · Jul 10, 2014 at 06:05 AM · iostouch

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Jul 10, 2014 at 06:06 AM 0
Share

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.

avatar image milkingcowboy · Jul 11, 2014 at 08:38 AM 0
Share

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.

avatar image MDarkwing · Jul 11, 2014 at 08:47 AM 1
Share

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?

avatar image louisgarcia · Jul 11, 2014 at 11:38 AM 0
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges