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
0
Question by Dreamhaxor · Mar 04, 2014 at 07:44 AM · gameobjectraycastcollidertag

Raycast starts ignoring gameobject after a few seconds

           Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
           RaycastHit hit;
           if (Physics.Raycast (ray, out hit, 1000))
           {
               switch (hit.collider.gameObject.tag)
               {
 
               case "HQ":
                  GetComponent<GUIscript>().Nothselected=false;
                  GetComponent<GUIscript>().Workselected=false;
                  GetComponent<GUIscript>().HQselected=true;
                  GetComponent<GUIscript>().SelectedBuilding=hit.collider.gameObject;
                  break;
 
               case "Worker":
                   GetComponent<GUIscript>().Nothselected=false;
                   GetComponent<GUIscript>().HQselected=false;
                   GetComponent<GUIscript>().SelectedBuilding=hit.collider.gameObject;
                   GetComponent<GUIscript>().Workselected=true;
                   hit.collider.gameObject.GetComponent<UniteMove>().selected=true;
                   break;
 
               case "Tile":
                  GetComponent<GUIscript>().Nothselected=true;
                  break;
               }
          }

why is it that after a few seconds Raycast starts ignoring all the workers no matter how many i spawn. it still doesn't ignore the HQ, but in case of the workers it goes through them and registers the tile. i don't ever mess with the collider or tag on worker. NOTE: the script does work for the first 2-3 seconds, and then it starts ignoring the worker.

Comment
Add comment · Show 6
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 robertbu · Mar 04, 2014 at 07:46 AM 0
Share

Put Debug.Log() statements to see what is going on. Between lines 4 and 5, add:

 Debug.Log(hit.collider.tag+", "+hit.collider.name);

The between lines 15 and 16 insert:

 Debug.Log("Worker found");
avatar image Dreamhaxor · Mar 04, 2014 at 07:53 AM 0
Share

it finds the worker just fine for the first few seconds, then it starts ignoring it and telling me i am clicking on the tile.

avatar image Berenger · Mar 04, 2014 at 08:28 AM 0
Share

Check the objects colliders and layers. $$anonymous$$aybe something else in your project is changing them ?

avatar image robertbu · Mar 04, 2014 at 08:31 AM 0
Share

So the issue is not with this code. If your Raycast() is reporting 'Tile', then this code can only process that as a 'Tile'. Next steps are 1) to verify the raycasts, and 2) verify the colliders. Use a Debug.DrawRay() and view your game in both Game view and Scene view while the game is running. Select some workers that the raycast are missing in the Hierarchy and take a look at the collider(s) on that game object. Have they been resized or disabled? Are you don't anything 'special' with the game objects or colliders such as using negative values for localScale?

avatar image Dreamhaxor · Mar 04, 2014 at 08:49 AM 0
Share

the raycasts are fine, the inspector says the capsule colider is fine, but here is the thing, i never do anything with the colliders, and yet even Physics.OverlapSphere fails to register the existence of the capsule coliders... what bugs me the most is that after the few seconds mark all the capsule colliders on all the workers fail to be registered, even though the inspector says everything is alright with them... If anything i think the Unity AI might have something to do with this (vague recollection tells me this started happening when i implemented the AI). here's the code for the AI if it helps any:

 public class Unite$$anonymous$$ove : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
 
     public bool selected=false;
 
     // Update is called once per frame
     void Update () {
 
       if (selected)
       {
           if (Input.Get$$anonymous$$ouseButtonUp(1))
           {
              Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
              RaycastHit hit;
              if (Physics.Raycast (ray, out hit, 1000))
              {
                 if(hit.collider.gameObject.tag=="Tile")
                 {
                         GetComponent<Nav$$anonymous$$eshAgent>().destination=new Vector3(hit.point.x,transform.position.y,hit.point.z);
                 }
              }
           }
       }
     }
 }
 
Show more comments

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

21 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

Related Questions

checking colliders from multiple raycast 1 Answer

How do you change the position of a Raycast? 1 Answer

RaycastHit collider not showing correct tags 1 Answer

Raycast from inside an object 2 Answers

"Player" tag collider from other GameObject? 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