Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
2
Question by Skyboard_Studios · Jul 22, 2015 at 09:00 PM · androidmovementbuttoninput.mouseposition

How to Ignore Input.MousePosition if button is pressed

I hope I can get some kind of a solution here...

  • Unity 5.1

  • Building for Android Platform

I have my player moving based on the input.mouseposition x and y so during a mouse/touch event on the screen the touch/mouse position is getting stored in a xy variable that then gets translated into a direction vector based upon the 2D's character center point...that is all good...

But the issue is when a user is going to touch a button for an in game action that the xy position of the touch get's relayed when the button is pressed and thus throwing the player in a non desired angle as a intended button action is pressed not a "movement press"....

so if the last movement angle is based on 200,100 and then the button is on the edge of the screen so a 500,600 things are not cool.... so the player will be heading at a 200,100 direction and once the button is pressed a immediate change of direction is triggered as the button's xy is way off from the 200,100 position...

So during the button press I need to ignore the input.mouseposition so that the player keeps on moving and the button's event doesn't pass the mouseposition's xy before button press...

I will try to see if I can make some kind of pretrap that once a button is pressed to not change the movements xy private variable...

Hard to describe.. I will try to perhaps make a video to describe the steps.. just trying to throw something out there to get some kind of working solution while I keep coding...

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

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Dave-Carlile · Jul 22, 2015 at 09:37 PM

Assuming your button is using the new GUI and Canvas and such...

 if (!EventSystem.current.IsPointerOverGameObject())
 {
   // we're not clicking on a UI object, so do your normal movement stuff here
 }
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 guetta18 · Aug 06, 2018 at 06:35 PM 0
Share

thank u very much!!

avatar image gmgoraj · Mar 15, 2019 at 05:23 PM 0
Share

Sometimes i cant belive simplest things are the best... thanks very much ;)

avatar image GothamN · Jul 31, 2020 at 07:02 AM 0
Share

wow! still helpful after five years...

avatar image
0

Answer by bubzy · Jul 22, 2015 at 09:35 PM

you could put your movement code inside a condition like

 //pseudocode
 
 if(mouseButton is not pressed)
 {
 process mouse coordinate
 }


this way it will just ignore the input.mousePosition when its pressed.

hope this helps (if i understood what you wrote properly)

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

26 People are following this question.

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

Related Questions

2D Vector Movement,Vectorel Movement with Buttons 2 Answers

Input lag on Andorid but not in Unity 1 Answer

How do I make my player jump on click on the button? 3 Answers

UI button shows in editor but not on mobile? 0 Answers

Animate Character movement? 1 Answer


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