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 TuberBacon · Feb 27, 2020 at 10:18 AM · collisioncollidertriggertouch controlsraycasthit2d

Missing taps on triggers/collider

I'm trying to make a falling object fly back up when the user taps it in the lower part of the screen.

 Rigidbody2D rb;
 void Update()
     {
         // 3 if()s for the tap detection (copypasted from documentation)
         if (Input.touchCount > 0)
         {
            Touch touch = Input.GetTouch(0);
             if (touch.phase == TouchPhase.Began)
                 {
                  RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(touch.position), Vector2.zero);
 
                     // if object is tapped AND tap is below the y = -2.5 coord.
                 if (Camera.main.ScreenToWorldPoint(touch.position).y <= -2.5f && hit.collider.isTrigger)
                 {
                     //shoot back up in random direction
                     float randx = Random.Range(-5f, 5f);
                     float randy = Random.Range(6f, 9f);
 
                     rb.velocity = new Vector3(randx, randy, 0f);
                 }
             }
         }
 }


The game works as intended on multiple devices but all share a problem. Sometimes Unity wouldn't register a tap on the object's collider and miss. I recorded and studied it frame by frame and it indeed sometimes doesn't read the tap even inside the collider area. I'm not even sure if it's physics, collision, trigger, tap-detection, or even frame per frame performance related (even though it runs smooth on old devices too, but modern ones still have the issue). I would like to avoid changing the timestep from 0.02 to 0.01 because that would mean change all Time.time and deltaTime in the code, but do tell me if it would help.

Another thread suggested to make the collider bigger/offset upwards to balance out a possible lag in the raycast-collider detection. Is this it?

Comment
Add comment · Show 3
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 Magso · Feb 27, 2020 at 11:14 AM 0
Share

Have you tried setting the fixed timestep lower? The physics framerate is independent of the game's framerate so no changes need to be made to deltaTime.

avatar image TuberBacon Magso · Feb 29, 2020 at 12:23 PM 0
Share

I did consider it but I don't know anymore what that would imply. Some sources say it would modify physics but you say it wouldn't, and this is without considering animations. I DID though fix the issue, or rather, ditched the raycast completely. I discovered that the On$$anonymous$$ouseEnter() function works with screentaps too and is so much more reliable and responsive for fast paced registers. And editing in unity is easier since I'm using the same input system. I don't know if it's wrong or not, but it works like a charm.

avatar image Magso TuberBacon · Feb 29, 2020 at 09:35 PM 0
Share

Some sources say it would modify physics but you say it wouldn't

It does. Fixed timestep shows the time in seconds between each physics frame. (a little weird when most engines set a 'physics fps' value, not a 'seconds' value)

Time.deltaTime is the time elapsed since the last frame which won't affect nor is affected by the physics framerate, Time.fixedDeltaTime is the time elapsed since the last physics frame.

0 Replies

· Add your reply
  • Sort: 

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

220 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 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 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 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 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 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 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 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 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

How can I detect a collision point, but allow player to pass through collider. 1 Answer

How to make work a collision when is invisible? 3 Answers

NPCs collide with collider but player does not 1 Answer

How to get collision point when using onTriggerEnter 5 Answers

Objects placed manually collide, but don't if instantiated? 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