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
1
Question by xikky · Jun 19, 2013 at 09:17 AM · inputdetecttouchphase

TouchPhase.Began not detected.

In my input script I am using touchPhase types to execute specific functions. My only problem is that TouchPhase.Began is not detected at any time both on Unity Remote and when build on android device. Is it possible to detect the TouchPhase.Began at all?

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 ahaykal · Jun 19, 2013 at 10:19 AM 0
Share

if you could show us your script maybe we could help you more. There could be many things going on

avatar image xikky · Jun 19, 2013 at 10:23 AM 0
Share

function FixedInputs () { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Began) { //Do something } } }

I am guessing now that this might happen because of the FixedUpdate. Am I right?

avatar image whydoidoit · Jun 19, 2013 at 10:25 AM 0
Share

Yes, don't use FixedUpdate for input.

avatar image xikky · Jun 19, 2013 at 10:27 AM 0
Share

What if I need to script input for movement of a rigidbody? Is there a better way rather then using FixedUpdate?

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Jun 20, 2013 at 01:14 AM

Don't use FixedUpdate for input. The problem with FixedUpdate is that it may run many times in a frame or not at all and there is no guarantee that events will be prepared properly when running it.

You need to get your input in a normal Update and then apply it to the rigidbody. If you are physically moving the body you want to set flags or some other method in your Update and then apply it on the next FixedUpdate. If you are adding forces you can do that anywhere. If it is kinematic then you can also move it anywhere.

Comment
Add comment · Show 8 · 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 xikky · Jun 21, 2013 at 11:53 AM 0
Share

Thanks for that, I didn't notice that I could Update since I am directly moving a Is$$anonymous$$inematic object which is jointed to the other rigidbody.

But I'm still having the same problem, this time with canceled. Inside Update i'm doing this:

 if (Input.touchCount == 1) {
     
     print(Input.GetTouch(0).phase);
 }

Canceled is never printed. This is strange :S. I guess I have to create my own trigger for no touch.

avatar image xikky · Jun 21, 2013 at 12:00 PM 0
Share

And I'm sure it's not a problem with fps because I've built it on my android, printing the phase OnGUI and fps is over 50

avatar image whydoidoit · Jun 21, 2013 at 12:02 PM 0
Share

Cancelled is an odd touch phase, are you sure you aren't looking for Ended?

avatar image xikky · Jun 21, 2013 at 12:11 PM 0
Share

I am just printing the Input.GetTouch(0).phase and it never prints neither Canceled nor Ended. And yes inside my original code, I am sure I was checking for Canceled. I also check for both - Cancelled || Ended. Even though I know that ended is fired when touches count are over the limit.

I am now doing this to check whether a touch is present or not:

 if (Input.touchCount == 1) {
     
     print(Input.GetTouch(0).phase);
 }
 else (Input.touchCount == 0)
     print("Nothing");

I would like to hear about any other better solutions if any :)

avatar image whydoidoit · Jun 21, 2013 at 12:14 PM 0
Share

If you iterate across the Input.touches collection do you find it? Rather than checking only when touchCount > 0?

Show more comments
avatar image
0

Answer by OmarAlhaddad · Jun 19, 2013 at 10:28 PM

This have worked for me every single time, in C# but JS should be similar.

 foreach (Touch evt in Input.touches) 
     {
         if (evt.phase == TouchPhase.Began) 
         {
             //...
         }
     }
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

18 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

Related Questions

Unity 2D Touch Controll via on screen button for Mobile 0 Answers

Get Touch touch phase began is grounded not working 2 Answers

Check for Ui clicks 0 Answers

Detect smartphone movement 0 Answers

When iOS framerate lags, are TouchPhase.Begans getting lost? 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