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 davidjohn123 · Jun 07, 2016 at 07:30 AM · touches

Detecting RayCast on moving object?

i have searched alot but could not find any refernce across internet. my case is gameobjects are spawning from the top of screen and translating downwords. each gameObject has trigger and a script that translating it. player have to tap on each object to destroy that specific gameobject. i am using raycasting to detect touch on each object. everything working if speed is normal. when object starts to come fast . the gameobject start ignoring touch. any solution for this? i have to scripts one attach to camera that manage raycasting and other translating tile

Script attached to camera

 using UnityEngine;
 using System.Collections;
 
 public class RaycastManager: MonoBehaviour {
     Touch touch;
     public bool stopTime=true;
     public float delay,timer;
     // Use this for initialization
     void Start () {
         timer = delay;
     }
     void Awake()
     {
         MoveTile.speed = 7f;
     }
     // Update is called once per frame
     void FixedUpdate () 
     {
         if (Input.touchCount >0) {
             //MoveTile.speed = 0f;
             touch = Input.GetTouch (0);
             RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint ((touch.position)), Vector2.zero);
             if (hit.collider.tag == "Pink") {
                 Destroy (hit.transform.gameObject);
             } else if (hit.collider.tag == "Green") {
                 Destroy (hit.transform.gameObject);
             } else if (hit.collider.tag == "Blue") {
                 Destroy (hit.transform.gameObject);
             } else if (hit.collider.tag == "SeaGreen") {
                 Destroy (hit.transform.gameObject);
             } else if (hit.collider.tag == "Purple") {
                 Destroy (hit.transform.gameObject);
             } else if (hit.collider.tag == "Orange") {
                 Destroy (hit.transform.gameObject);
             } 
         }
     }
     
 
 }
 

Script attached to each gameobject

 using UnityEngine;
 using System.Collections;
 
 public class MoveTile : MonoBehaviour {
     public float speed;
     // Use this for initialization
     public void pointerDown () 
     {
         speed = 0;
         gameObject.SetActive (false);
     }
     
     // Update is called once per frame
     void Update () {
         transform.Translate (speed  * Vector2.down*Time.deltaTime);
 
         }
 
 }

Comment
Add comment · Show 1
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 ahmedhassan288 · Aug 23, 2016 at 11:58 AM 0
Share

I need to know the solution pls!?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by giorashc · Jun 07, 2016 at 08:39 AM

Since you are translating your objects in Update() (instead of FixedUpdate()) then in high speeds the raycast check point might miss the actual object since Update() might be called several times between two sequential calls to FixedUpdate(). So while you check the input and raycast in FixedUpdate the object might already been translated.

Check this link about the differences regarding being in sync with the physics engine.

Try translating your objects in a FixedUpdate() method instead of in Update()

Also do raycasting checks in Update() method as FixedUpdate() is executed in fixed intervals while Update() is called per frame (which on higher fps is more frequent the FixedUpdate()).

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 davidjohn123 · Jun 07, 2016 at 08:53 AM 0
Share

giorashc Thanx Alot for your reply. I tried to shift translation into fixed upadate. but face same issue.. i tried another technique my making all gamobject ui image and added event trigger on them and using "on pointer down" i achieve the same target but issues is still same. hight speed cant be handle with both techniques

avatar image davidjohn123 · Jun 07, 2016 at 08:56 AM 0
Share

is unity not capable of handling high speed gameobjects?

avatar image giorashc davidjohn123 · Jun 07, 2016 at 09:02 AM 0
Share

It sure does... it just needs to be handled right. Did you try putting logs (Debug.Log(..)) around your updates to understand what exactly happens in which order?

avatar image davidjohn123 · Jun 07, 2016 at 09:18 AM 0
Share

i checked using logs
"'RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint ((touch.position)), Vector2.zero)""; the hit is racast is not colliding with the collider of gamobject. can say ignoring collision.

avatar image giorashc davidjohn123 · Jun 07, 2016 at 09:22 AM 0
Share

When you say 'everything working if speed is normal' you mean that the raycast works (or the event trigger works)?

avatar image davidjohn123 · Jun 07, 2016 at 09:24 AM 0
Share

both things work in normal speed. event triggers and raycast but when speed of gameobject increase the problem arise.

avatar image davidjohn123 · Jun 07, 2016 at 09:25 AM 0
Share

its piano tiles like game and speed of tiles increase with span of time.

Show more comments
avatar image
0

Answer by davidjohn123 · Jun 13, 2016 at 06:08 AM

I find solution of this problem after a week of struggle. if someone need solution can contact me.

Comment
Add comment · Show 5 · 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 ammar_intertactive_notion · Jul 19, 2016 at 09:46 AM 0
Share

Hey $$anonymous$$. I am stuck in same situation ,so where to contact you? can you post your email here .

avatar image davidjohn123 · Aug 12, 2016 at 10:05 AM 0
Share

yes why not @ammar

avatar image ahmedhassan288 · Aug 23, 2016 at 11:42 AM 0
Share

I need to know the solution plz?!, Thanks!

avatar image davidjohn123 · Aug 25, 2016 at 07:40 AM 0
Share

@ahmedhassan my skype husnain.yousaf88

avatar image GiorgioTurro · Jul 17, 2018 at 09:11 AM 0
Share

Hey, can you post the solution?

avatar image
0

Answer by Brijs · Jun 13, 2016 at 06:37 AM

Use OnMouseDown()

OnMouseDown reference

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

8 People are following this question.

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

Related Questions

trouble with input touches 1 Answer

From Input.GetMouse to Input.touch. Multi-touch and raycasts? 1 Answer

How to use multi touch 0 Answers

Problem with Input.touchCount 0 Answers

Moving GameObjects with multiple touches! 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