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 Barbritnix · Jun 10, 2019 at 10:01 AM · 3dcollision detectioncollision issues

How to Check if you are Colliding with more than one object with the same tag?

I have a problem with collision in my project. I am using a weird flappy bird model I made. It has a beak, 2 eyes, and 2 black pupils. All of those are marked with the same tag in my project. I am also using a death counter and whenever the front of the model hits something that'll kill you, The death counter goes up by 3-5 times. So I want to check that if there is more than one of the same tag colliding with a dangerous object, It will add only one to the death counter.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class FailLevel : MonoBehaviour
 {
     public string strtag;
 
     private void OnCollisionEnter(Collision collision)
     {
         if (collision.collider.tag == strtag)
             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
         DeathCounter.NumOfDeaths += 1;
     }
 }

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

2 Replies

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

Answer by TheGameLearner · Jun 11, 2019 at 06:07 AM

Add a large Collider and keep it simple.
However, if you have the need for multiple colliders, Use the detection in Dangerous Object and ask it to send a count to the bird. This way, you can avoid problems.
If this too is something you can not do, or do not wish to do, then use Points array in the collision to detect each collision point and check the dangerous objects the points and other collider belongs to. This approach though a little confusing can give you perfect results.

Comment
Add comment · Show 4 · 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 xxmariofer · Jun 11, 2019 at 07:17 AM 0
Share

having multiple little colliders with only one rigidbody is the same as just one big one

avatar image Barbritnix · Jun 11, 2019 at 08:35 AM 0
Share

The script I posted is used by the dangerous object. And how do you add a large collider? I tried removing all the parts' colliders and put a mesh collider on the empty object which contains all the parts of the bird and It keeps falling to the ground. (Sorry for being Naive btw, I'm new to this)

avatar image Barbritnix · Jun 11, 2019 at 08:38 AM 0
Share

Wait Never$$anonymous$$d. I finally figured it out. I just had to remove all the colliders of all the parts except for the body and it finally works. Thank you

avatar image TheGameLearner Barbritnix · Jun 11, 2019 at 10:27 AM 0
Share

$$anonymous$$ost welcome :)

avatar image
1

Answer by xxmariofer · Jun 10, 2019 at 10:23 AM

remove the rigidbodys for the different parts, the bird should only have 1 rigibdody

Comment
Add comment · Show 4 · 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 Barbritnix · Jun 11, 2019 at 04:07 AM 0
Share

None of the parts have a rigid body except for the empty object where all the parts belong to

avatar image xxmariofer Barbritnix · Jun 11, 2019 at 07:17 AM 0
Share

then is imposible to receive multiple oncollisionenter messages, since if the parent has a rigidbody and the childs doesnt it will be consider one big rigidbody, and you would only receive the message once, what i would suggest you is trying to debug.log the collision.transform.name so you make sure what body is colliding, and adding the event oncollisionexit to make sure the body is not exiting hte collider

avatar image Barbritnix xxmariofer · Jun 11, 2019 at 08:26 AM 0
Share

I tried using the debug.log thing. And It showed me 5 messages. Left Pupil, Left Eye, Body, Right Pupil, Right Eye

avatar image Barbritnix · Jun 11, 2019 at 08:40 AM 0
Share

Never$$anonymous$$d, I figured it out. I just had to remove all the colliders of the bird except for the body itself and it works

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

132 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

Related Questions

3D Raycast Corner Collision 0 Answers

Two different spheres attached to one object for collisions 0 Answers

Character Controller collisions on older version no longer working? 1 Answer

How to Have Two Child Objects of One Parent Detect Collisions Between Eachother. 1 Answer

Is there a way to check for models stuck inside models?(see attached images) 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