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 Eco-Editor · Jun 22, 2017 at 10:29 AM · collisionlogcountcollisiondetection

many collisions while holding an item

Hello all,

I'm sending a massage to the log file when I pick an Item with HTC Vive controller. in my log file I get this:

Picked item, name : AppleRed at: 6/25/2017 5:43:17 PM

Picked item, name : AppleRed at: 6/25/2017 5:43:17 PM

Picked item, name : AppleRed at: 6/25/2017 5:43:18 PM

Picked item, name : AppleRed at: 6/25/2017 5:43:18 PM

Picked item, name : AppleRed at: 6/25/2017 5:43:18 PM

I understand that it might be because it counts several collision per frame, while I hold the item with the controller, can this be fixed?

I attach the script for reference.

     private void SetCollidingObject(Collider col)
     {
         if (collidingObject || !col.GetComponent<Rigidbody>())
         {
             return;
         }
       collidingObject = col.gameObject;

      if (col.gameObject.tag == "Item")
         {
             LogManager.AddLine("\n\n" + "Picked item, name : " + col.gameObject.name);
         } 
     }







Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EpsilonQoppa · Jun 25, 2017 at 11:42 PM

Maybe try something like this..

     bool m_CollisionEnabled = true;
     void OnCollisionEnter(Collision collision)
     {
         if (m_CollisionEnabled)
         {
             m_CollisionEnabled = false;
 
             //Insert Functions Inbetween
 
             StartCoroutine(EnableCollision());
         }
     }
 
     IEnumerator EnableCollision()
     {
         yield return new WaitForEndOfFrame();
         m_CollisionEnabled = true;
     }
Comment
Add comment · Show 3 · 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 EpsilonQoppa · Jun 25, 2017 at 11:45 PM 0
Share

Now that I think about it, you may be better off waiting for half a second or so ins$$anonymous$$d of a frame because they could still be touching the next frame.

avatar image Eco-Editor EpsilonQoppa · Jul 12, 2017 at 07:46 AM 0
Share

Ok, I've referenced he collider col in the IEnumerator, and it gives me an error.... UH!

         collidingObject = col.gameObject;
         if (m_collisionEnabled)
         {
             m_collisionEnabled = false;
             StartCoroutine(EnableCollision(collider col)); //GOT ERROR HERE
         }
     }
 
     IEnumarator(Collider col) //REFERENCED here
     { 
       if (col.gameObject.tag == "Item")
         {
             yield return new WaitForSeconds(3);
               col.gameObject.GetComponent<Rigidbody>().useGravity = true;
                col.gameObject.GetComponent<Rigidbody>().is$$anonymous$$inematic = false;
             m_CollisionEnabled = true;
         }
 
     }

I get it all the time. I try to add a variable within the function title and then not be able to reference that function...

avatar image Eco-Editor · Jul 12, 2017 at 07:41 AM 0
Share

Not sure it's a good fix @$$anonymous$$roq
because my lines use col.gameObject.GetComponent<>()

which is not known in the IEnumerator function.

     private void SetCollidingObject(Collider col)
     {
         if (collidingObject || !col.GetComponent<Rigidbody>())
         {
             return;
         }
 
         collidingObject = col.gameObject;
         if (m_collisionEnabled)
         {
             m_collisionEnabled = false;
 
         }
       if (col.gameObject.tag == "Item")
         {
               col.gameObject.GetComponent<Rigidbody>().useGravity = true;
                col.gameObject.GetComponent<Rigidbody>().is$$anonymous$$inematic = false;
         }




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

101 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

Related Questions

Pixel Perfection collision on 3d animated object 0 Answers

Find axis of collision 0 Answers

Checking Collision on instantiated object 0 Answers

How do I make OnTriggerEnter() respond to just one collider? 2 Answers

Unity changes the collisionDetectionMode in builds 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