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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by GiLA94 · Jun 10, 2014 at 03:39 PM · rigidbodyraycastinputtouchfalling

Touching Falling Objects

Hi, here's my problem. I have cubes spawned at the top of the screen and falling down because of gravity. Touching a cube makes it disappear and increase the score. it works pretty good but as the speed gets higher the touch seems not working.

I've already tried editing the timestep values and other time settings in the Edit>project settings>Time tab, without any good result.

here's my code, any help is appreciated.

 foreach (Touch t in Input.touches) {
                     if (t.phase != TouchPhase.Moved && t.phase != TouchPhase.Stationary) {
                         RaycastHit hit;
                         Ray ray = Camera.main.ScreenPointToRay (t.position);
                         if (Physics.Raycast (ray, out hit, 100f)) {
                             if (hit.collider.gameObject.tag == "cube") {
                                //SCORE UPDATE AND DESTROY() HERE                            
                             }
                         }
                     }
   }
Comment
Add comment · Show 2
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 HarshadK · Jun 10, 2014 at 03:43 PM 0
Share

One of the reason for this to happen is that since physics and rendering are independent your object might not be physically at the place where it is rendered if it is moving at great speed.

Can you use Debug.Log to check the position of your cube and related positions for input? That might help understanding the problem better.

avatar image darthbator · Jun 10, 2014 at 11:20 PM 0
Share

I don't think that should happen very often. In order for the physics system to do that you would need to be rendering @ < 60FPS.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by darthbator · Jun 10, 2014 at 11:26 PM

Sometimes when I deal with something like this I will end up casting a sphere and not a ray. This kind of allows you do hit a "broader" spectrum of world space then a ray.

http://docs.unity3d.com/ScriptReference/Physics.SphereCast.html

I find lots of touch input to be pretty imprecise. Think about it when you put your finger down you are touching WAY more then 1 screen coordinate location. I often find the circle or sphere casts/checks to be a better representation of a players actual touch then a ray is.

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 GiLA94 · Jun 12, 2014 at 08:43 AM 0
Share

the code is now as follows: foreach (Touch t in Input.touches) { if (t.phase != TouchPhase.$$anonymous$$oved && t.phase != TouchPhase.Stationary) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay (t.position); if (Physics.SphereCast (ray,1,out hit,100)) { if (hit.collider.gameObject.tag == "cubo") {

but still, it looks like it's really imprecise and it misses the cubes quite often as they become faster. the FPS rate is over 50 for the duration of all the game.

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

22 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

Related Questions

Falling object touch 0 Answers

raycast hit add force problem, help needed please 1 Answer

Detect if dragged over object 1 Answer

Getting raycast to fire at touch position but only when second finger is on screen 0 Answers

How to drag and drop a instantiate prefab on my mobile game 3D using touchs! 0 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