• 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
7
Question by ina · Oct 29, 2011 at 04:56 AM · inputmobiletouchmousepositiontouchscreen

Input.mousePosition equivalent to first finger touch?

is unity's input.mousePosition equivalent to first finger touch in mobile and touchscreens?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
14

Answer by Firemaw · May 27, 2015 at 12:29 PM

On a touch device:

The above answers are correct only if you are touching with one finger at a time. When there is more than one touch active at the same time, Input.mousePosition is actually the average of all touch positions in the Input.touches array.

Another difference is that where there are no touches, you might expect Input.mousePosition to return zero, but it doesn't. It remains at the position the last touch or touches were released (as if you "let go" of the mouse).

All of this said, you should be using platform-specific code that references either Input.mousePosition or the Input.touches array for your logic (use the Platform Dependent Compilation defines or the Application.platform variable).

Comment
Add comment · Show 1 · 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 infinitypbr · Jan 15, 2016 at 06:22 AM 0
Share

How about if I want to have both on the same app? Some devices have touch screens and a mouse now -- I'd like to have both active, but I do NOT want the first finger touch to activate Input.GetAxis("$$anonymous$$ouse X") or Y.

Is that possible?

avatar image
2

Answer by GoSuNeem · Oct 30, 2011 at 01:10 AM

If you are talking about Touch inputs, check the following links.

http://unity3d.com/support/documentation/ScriptReference/Touch.html http://unity3d.com/support/documentation/ScriptReference/Input.html

To pull the info of 1st touch, use the fingerID to check if it's the first touch. To get the positions, use the touch position. Try using Input.GetTouch(0).position.

Good luck!

Comment
Add comment · Show 3 · 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 ina · Oct 30, 2011 at 05:49 AM 0
Share

Input.mousePosition appears to be equivalent to the first touch point. Try it!

avatar image GoSuNeem · Oct 30, 2011 at 06:04 AM 2
Share

Oh whoops! Sorry. Thought u were asking from $$anonymous$$ouse input -> Touch not the other way.

Anyways, Yes Input.mousePosition is same as touch.position.

button click downs are... Input.Get$$anonymous$$ouseButton(0)

http://unity3d.com/support/documentation/ScriptReference/Input.Get$$anonymous$$ouseButton.html

Input.mousePosition is the position of the mouse (Vec2)(x,y)

http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

Sorry about the confusion.

avatar image ina · Oct 30, 2011 at 10:48 PM 1
Share

it looks like Input.mousePosition actually returns a Vector3 with z coordinate 0, while Input.touch.position returns just a Vec2...

avatar image
1

Answer by gaps · Feb 10, 2014 at 09:12 PM

If using the mouse input is "equivalent" to using the first finger touch input... When considering a touch: yes; when considering the actual mouse: no.

The first touch simulates the mouse input, so if you use Input.mousePosition, it will work both with the actual mouse and the first touch. But the opposite does not happen, i.e. if you are just handling the touches, the mouse won't simulate that, so your code will only work on touch devices.

EDIT: To answer the comments, you can use Input.simulateMouseWithTouches = false; if you want to disable the mouse simulation with the touches (it is enabled by default).

Comment
Add comment · Show 3 · 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 infinitypbr · Jan 15, 2016 at 06:21 AM 1
Share

Any idea how to STOP this from happening? Googling for an answer is terrible, most of the results are questions on how to get touch input working :)

But seriously -- this is frustrating me. I want both mouse AND touch inputs to work on the same game at the same time, for devices that have both.

However the first touch always activates Input.GetAxis("$$anonymous$$ouse X") & Y. I can't see how to turn this off for touch.

avatar image Mikael-H infinitypbr · Apr 25, 2017 at 04:12 PM 0
Share

@sfbaystudios me too, did you ever find a way to tell them apart?

avatar image David-Williamson infinitypbr · May 06, 2019 at 10:09 AM 0
Share
 Input.simulate$$anonymous$$ouseWithTouches = false;

Disables the default behaviour.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

,How Do get Touch input to work with the Player Input Component 1 Answer

OnTouch function? 3 Answers

Possible to get touch area data? 1 Answer

MobileSingleStickControl Question 2 Answers

InputSystem simulated touchscreen stops working from v1.1.0 preview 1 0 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