• 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 /
  • Help Room /
avatar image
1
Question by Destanci · Jul 30, 2018 at 10:46 AM · collisioncollision detectioncollisionscollision issuescollision.contacts

How Can I Know which collider has call OnCollisionExit() on the script's gameObject??

In Code I Have Writed. im trying to know my plane have landed. then i need to know all my wheels is Ground. but i need to do it like this :

     [SerializeField]  // for see whats going on
     private List<bool> inContact = new List<bool>();
    
 
     [Header("Options :")]
     public List<Collider> Wheels;
     // Will Set it From inspector.
 
     void Start()
     {
         foreach (Collider col in Wheels) inContact.Add(false);
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if (Wheels.Contains(collision.contacts[0].thisCollider))
         {
             inContact[Wheels.IndexOf(collision.contacts[0].thisCollider)] = true;
             // Knowing That Wheel is inTouch.
         }
     }
 
     private void OnCollisionExit(Collision collision)
     {
         if (Wheels.Contains(collision.contacts[0].thisCollider))
         {
             inContact[Wheels.IndexOf(collision.contacts[0].thisCollider)] = false;
             // Trying To Know That Wheel Take-Off
         }
     }

This is not working because collision.contacts.Length is 0 at OnCollisionExit. Then This way cannot help me, But i need To know which MY collider called OnCollisionExit function because this plane have too much Collider and i just need wheels...

(After Edit)

I Did What i Want.

This Code For Landing Areas:

 public class LandAreaScript : MonoBehaviour
 {
     private void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.tag == "Player" && collision.gameObject.GetComponent<PointSystem>() != null)
         {
             collision.gameObject.SendMessage("GetLanded", collision.collider);
         }
     }
 
     private void OnCollisionExit(Collision collision)
     {
         if (collision.gameObject.tag == "Player" && collision.gameObject.GetComponent<PointSystem>() != null)
         {
             collision.gameObject.SendMessage("GetTakeOff", collision.collider);
         }
     }
 }

And This for my plane:

 public class PointSystem : MonoBehaviour
 {
     [SerializeField]  // for see what is going on
     private List<bool> inContact = new List<bool>();
 
     [Header("Options :")]
     public List<Collider> Wheels;
     // Will Set it From inspector.
 
     void Start()
     {
         if (Wheels.Count == 0) this.enabled = false;
         foreach (Collider col in Wheels) inContact.Add(false);
     }
 
     public void GetLanded(Collider Input)
     {
         if (Wheels.Contains(Input))
             inContact[Wheels.IndexOf(Input)] = true;
     }
 
     public void GetTakeOff(Collider Input)
     {
         if (Wheels.Contains(Input))
             inContact[Wheels.IndexOf(Input)] = false;
     }
 }

It is working now. But at other projects

Am i need to Set this LandAreaScript to all objects???

No way to do That. Will not Optimize.

I Get Dissappointed by Unity.

WHY THERE IS NO WAY TO GET COLLIDER which one at same object with script?

We need a Read-only variable at Collision Class like "thiscollider".

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 CamSEgeland · Feb 27, 2020 at 11:39 AM 0
Share

Did you ever find a solution to this? I also need thisCollider on OnCollisionExit()

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Feb 27, 2020 at 02:53 PM

Hello.

MAybe you are focusing in the worng direction. A solution can be to have a collider+sript in each wheel. In this script you detect the collisions for that specyfic wheel, and have some public bool variable to determinate if the wheel is grounded or not.

From your "general" script then, check for all this bools in each wheel script, so no need to know the number of collisions finished or started, you just check for the bool variable state.

This works for you?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

207 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

problems with collisions on flight script 0 Answers

Detecting collision altho disabled on matrix. Help!! :'( 0 Answers

Box Collider Working Sparadically,Box Collider Sporadically Working 0 Answers

Player cannot destroy enemy 1 Answer

Colliders for tunnels 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