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 Syahroyni · Jan 28, 2016 at 04:33 PM · collisioncolliderobjecttriggers

How to check which colliders that collision with some object ?

Hai guys. I have a problem with my car racing game especially in collider for NPC. I have 4 colliders to trigger some action in my NPC but I'm still don't know how to check which collider that collision with some object.

The two collider in front of car are use to make decision in my NPC that want to avoid the obstacle in front of the car. If the right one hit the obstacle, the car will turn left to avoid the obstacle and vice versa. But if both of them hit the obstacle, the NPC will activate the two collider beside the car and check the obstacle again for making decision that the NPC will turn left or right.

This is a picture about my NPC which have 4 colliders.

Thanks

Syahroyni Colllider in my NPC

Thanks

Syahroyni

roni-2.png (34.9 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by flashframe · Jan 28, 2016 at 06:51 PM

Instead of having four colliders on one game object, try attaching a collider to four separate child objects.

Then write a script with an OnTriggerEnter() function that calls a method in your main script and passes the name of the child object. (You'll need to reference the main object's script in your child objects).

     //in script on child object
 public MainScript mainScript //whatever your script is called - attach in inspector
 void OnTriggerEnter()
     {
         mainScript.CarImpact("LeftTrigger");
     }
 
 //in main script
     public void CarImpact(string trigger)
     {
         switch(trigger)
         {
         case "LeftTrigger":
             //do something
             break;
 
         }
     }
Comment
Add comment · Show 1 · 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 Syahroyni · Jan 29, 2016 at 06:30 AM 0
Share

Yeaaa. Its work. Thank you flash frame. But, I have one question again. How if the trigger collider hit an obstacle in same time ?

avatar image
0

Answer by Vagonn · Jan 28, 2016 at 04:38 PM

Attach this script to car

 public class Car()
 {
       void OnTriggerEnter(Collider other)
       {
              Debug.Log(other.name);
       }
 }

Comment
Add comment · Show 2 · 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 Syahroyni · Jan 28, 2016 at 05:55 PM 0
Share

Yeahh, I already try this before, but the other name is the wall's collider not my car's collider.

avatar image Vagonn · Jan 29, 2016 at 05:45 AM 0
Share

Then you must attach this to colliders seperately

avatar image
0

Answer by Astraphobia95 · Jan 28, 2016 at 05:38 PM

Check out the collision functions for the Monobehaviour class, you'll need to write some scripts to get what you want to work.

Comment
Add comment · Show 1 · 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 Syahroyni · Jan 28, 2016 at 05:56 PM 0
Share

yeahh, I already write the script. I use OnTriggerEnter. But that method doesn't give me the name of car's collider that hit the wall. That method return the name of wall collider.

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

6 People are following this question.

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

Related Questions

Can an object to transfer to another as it increases your speed? 1 Answer

Picked up objects passes through objects 2 Answers

how to check if one object is colliding with another 1 Answer

Colliders coming away from their parent object? 1 Answer

changing gravity OnTriggerEnter 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