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 uberalles · Feb 22, 2014 at 04:01 AM · raycastcolliderraycastingnavigation

Bug with navigation and raycasting

I'm having a problem with raycasting on objects that have a NavMeshAgent. After about 15-20 seconds or so I can no longer target my unit GO. It's as though the collider for that GO has disappeared. I saw that this issue was brought up about a year and a half ago but is it still a known issue/bug? Am I better off with A* ? Thanks.

P.S. I posted this in the forums but couldn't get a reply and I'm really stuck here.

Comment
Add comment · Show 15
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 whydoidoit · Feb 22, 2014 at 04:03 AM 0
Share

Ok never heard of that - but could be a fault - if you look at the scene while you are playing can you see the collider in place on the agent? If you Debug.DrawRay your raycast does it change or not intersect for some reason?

avatar image uberalles · Feb 22, 2014 at 04:46 AM 0
Share

I added a screenshot of the DrawRay. Goes right through the object. It works for the first little bit. One thing I have noticed is that at first I can click anywhere on the model and it selects it, but eventually you have to move further down the body to get it to select. Thanks for the reply, very frustrated with this problem.alt text

raycast_screen.jpg (98.1 kB)
avatar image whydoidoit · Feb 22, 2014 at 04:48 AM 0
Share

(Converted your "answer" to a comment - hit the add new comment button hiding on the right if you aren't posting a solution).

Yep that is definitely very strange. Would you $$anonymous$$d posting your code for the raycast and draw ray just so I can sanity check it for you? Is that a compound collider or is it possible you are hitting a different collider first with the ray?

avatar image uberalles · Feb 22, 2014 at 04:57 AM 0
Share

This class has a fair bit going on so I'm not sure if you really dive too far into it.

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$ouseControls: $$anonymous$$onoBehaviour {
 
     RaycastHit hit;
 
     //gameobject selection arrays/variables
     public static ArrayList currentSelectUnits = new ArrayList();//arrayList of Crew objects
     public GameObject currentUnit;
     public static ArrayList unitsOnScreen = new ArrayList();
 
     //Right-click destination object variables
     public GameObject crewDest;
     public GameObject destObj;
     //private float destBoxSize = 15f;
     private GameObject[] crewDestArray;
 
 
     //clicking variables
     private static Vector3 leftDownPoint;
     private static float clickDragZone = 1.3f;
     private static float doubleClickDelay = .35f;
     public  float doubleClickRemain;
     private bool one_click = false;
     public bool checkRotating;
     private Vector3 rightDownPoint;
     public float rotateClickTimer = 0f;
 
     private int addOn = 5;
 
 
 
     void Awake()
     {
         leftDownPoint = Vector3.zero;
         checkRotating = false;
         rightDownPoint = Vector3.zero;
         crewDest = Instantiate(destObj, new Vector3(10,0,10),transform.rotation) as GameObject;
         crewDestArray = new GameObject[2];
         crewDestArray[0] = crewDest;
 
         for(int i = 1;i<2;i++)
         {
             crewDestArray[i] = Instantiate(destObj, new Vector3(10,0,10 + (addOn * i)),transform.rotation) as GameObject;
 
         }
     }
avatar image uberalles · Feb 22, 2014 at 04:58 AM 0
Share

void Update () { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, out hit,$$anonymous$$athf.Infinity)) { Debug.DrawLine (ray.origin,ray.direction * 5000,Color.red);

         if(Input.Get$$anonymous$$ouseButtonDown(0))//when user first clicks the mouse down, potentially starting a mouse drag
         {
             leftDownPoint = hit.point;
             
             if(!one_click)//first click
             {
                 one_click = true;
                 doubleClickRemain += Time.deltaTime;
             }
             else
             {
                 
                 if(doubleClickRemain > doubleClickDelay)
                 {
                     //basically if thats true its been too long and we want to reset so the next click is simply a single click and not a double click.
                     one_click = false;
                 }
                 else//this is a double click
                 {
                     
                 }
             }
         }
         //check to see if enough time has passed in order to remove the first click, if there is one

         //$$anonymous$$ouseClick   
         else if(Input.Get$$anonymous$$ouseButtonUp(0) && didUserClickLeft$$anonymous$$ouse(hit.point))
         {

             if(hit.collider.name == TagName.ground_name)
             {    
                 deselectGameObjectIfSelected();
             }
             else if(hit.collider.tag == TagName.gangster_tag)
             {
                 //Debug.Log("Parent: " + hit.transform.parent.GetComponent<Crew>().gangList.Length);

                 if(!unitAlreadySelected(hit.collider.gameObject))//If unit is not already selected
                 {
                     //Get the Crew script from the selected gangster, then select the entire Crew and add the script to the currentSelectUnits list
                     //moving and setting the selection should all be done within the Crew script.

                     if(!shift$$anonymous$$eysDown())//if the neither of the shift keys are pressed
                     {
                         deselectGameObjectIfSelected();
                         currentUnit = hit.collider.gameObject;
                         
                         Crew c = currentUnit.transform.parent.GetComponent<Crew>();
                         c.SetSelected(true);
                         //currentUnit.transform.Find(TagName.select_display).gameObject.SetActive(true);
                         currentSelectUnits.Add(c);
                     }
                     else
                     {

                         if(unitAlreadySelected(hit.collider.gameObject))
                         {
                             removeUnitFromSelected(hit.collider.gameObject);
                         }
                         else
                         {
                             currentUnit = hit.collider.gameObject;
                             
                             Crew c = currentUnit.transform.parent.GetComponent<Crew>();
                             c.SetSelected(true);
                             //currentUnit.transform.Find(TagName.select_display).gameObject.SetActive(true);
                             currentSelectUnits.Add(c);
                         }
                     }

                     

                 }                    
                 
             }//end of if hit collider crew
         }//end of mouse click input
             
         #endregion

     
     #region right click
     else//if left mouse button has not been clicked, then compute right click stuff
     {
         
         if(Input.Get$$anonymous$$ouseButtonDown(1))
         {
             rightDownPoint = hit.point;
         }
         else if(Input.Get$$anonymous$$ouseButton(1))
         {
             if(!checkRotating)
                 rotateClickTimer += Time.deltaTime;
             if(rotateClickTimer > .5f && !checkRotating)
             {
                 checkRotating = true;

             }
             if(checkRotating)
             {
                 crewDest.transform.LookAt(hit.point);
             }
         }
         
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by unimechanic · Feb 24, 2014 at 09:19 PM

To answer your last comment:

So when I turn off the NavMeshAgent selection works just fine and the problem seems to be gone. Anyone know what about the NavMeshAgent that could be causing this or should I report a bug?

Yes, please submit a bug report with a minimal sample project (if possible, will be very helpful) that reproduces this problem, following these guidelines and additional information:

http://unity3d.com/BugReportingFAQ http://blogs.unity3d.com/2013/10/28/bug-reports-incidents-and-some-bashing/ http://issuetracker-staging.unity3d.com/

The bug reporting tool is next to the Unity executable if you can't run it from the editor. Our QA team will review the issue as soon as possible, and then assign it to our developers. Having the bug report is the only way this problem can be fixed.

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

20 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

Related Questions

raycast not colliding 1 Answer

Multiple hit detection with Raycasting? 2 Answers

Raycast not hitting collider 2 Answers

Fixing Editor Mouse Offset Due To Local Raycast? 1 Answer

SInce when?!?!? (Raycast issue) 2 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