Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kamiccolo · Mar 30, 2016 at 08:43 PM · inputmobileiphonetouchgetmousebutton

Issue with Input.GetMouseButton (0) on mobile (iPhone)

In my game, if a user holds down the left mouse button, a jetpack will rise in the air with flames ignited. This thrust actively works against gravity. When the thrust turns off, the flames will go out and gravity will cause the jetpack to fall.

This works perfectly in Unity. On my iPhone, however, the jetpack will not lift off the ground. Instead is stutters on the ground when the screen is being touched. The flames, however, do show and hide correctly when the screen is being touched / not touched, therefore I know it is reading the input correctly. Perhaps there seems to be an issue with the physics that only happens on the phone?

Does anyone have any ideas? Thanks!

 void Update () {
     if (Input.GetMouseButton (0)) {
         //    Show flames
         thrustObject.SetActive(true);

         //    Force that works when using the mouse, but not when on my iPhone screen
         rb.AddForce (new Vector2 (0, thrust), ForceMode2D.Impulse);
     } else if (Input.GetMouseButtonUp(0)) {
         //    Hide flames
         thrustObject.SetActive(false);
     }
 }
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
0
Best Answer

Answer by kamiccolo · Mar 31, 2016 at 10:01 AM

FixedUpdate seems to be necessary on mobile. My guess is that it has to do with varying frame rates on different devices that perform differently. The fact that there is no Time tracking on ForceMode2D.Impulse makes me lean more towards this assumption.

 void FixedUpdate () {
      if (Input.GetMouseButton (0)) {
          //    Show flames
          thrustObject.SetActive(true);
          //    Force that works when using the mouse, but not when on my iPhone screen
          rb.AddForce (new Vector2 (0, thrust), ForceMode2D.Impulse);
      } else if (Input.GetMouseButtonUp(0)) {
          //    Hide flames
          thrustObject.SetActive(false);
      }
  }
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 halilkayim · Apr 26, 2018 at 01:35 PM 0
Share

The reason why this happens is that Update is called before every frame update, whereas FixedUpdate is called before every physics update. The frame rate may change throughout the game which would cause Update to be called less frequently, but FixedUpdate is called in the same interval regardless of the frame rate. So the visual part works correctly because it is called before the screen renders, but the stuttering happens because the force is added only on Update, which is not necessarily called on every physics update.

avatar image
0

Answer by ShadoX · Mar 31, 2016 at 07:41 AM

Try having a look at http://docs.unity3d.com/Manual/MobileInput.html

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 kamiccolo · Mar 31, 2016 at 09:25 AM 0
Share

Input.Get$$anonymous$$ouseButtonUp(0) does work as a valid default input on mobile devices. Also the phone is reading the input just fine, as seen with the jetpack's flames. Thanks anyway though.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Tie touch logic into InputManager 0 Answers

How to differentiate touches on mobile devices 1 Answer

Mobile - button press while moving (First Person Controls) 0 Answers

Does Unity Remote 4 act the same as it would when it is on the app store? 1 Answer

Input.mousePosition equivalent to first finger touch? 3 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