• 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
12

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.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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 to make responsive Touch inputs? 1 Answer

Touch Input positions are different on iOS and Android? 2 Answers

Problem with Vector3 Distance and Mouse Input, 1 Answer

How to add touch input for mobile devices using unity? 2 Answers

OnTouch function? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges