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 /
  • Help Room /
avatar image
0
Question by Hubinga · Aug 16, 2017 at 01:11 PM · scripting problemcolliderissue

Collision Issue! PLEASE GUYS HELP ME!

I want to create a game like BubbleShooter and when i shoot a bubble (as u can see in the image) the Console shows a message with the colliders the bubble hit. But i dont get why there are so many colliders when i only hit one bubble? Thank you in advance

Script:

public class PopBubble : MonoBehaviour {

 PlayerController player;

 void Start()
 {
     GameObject playerobject = GameObject.FindWithTag("Player");

     player = playerobject.GetComponent<PlayerController>();
 }

 void OnCollisionEnter(Collision other)
 {
     if(other.collider.gameObject.name == player.instantiatedobj.name)
     {
         //Destroy(other.gameObject);

         //Destroy(player.instantiatedobj);

         Debug.Log("collide (start)(name) : " + other.collider.gameObject.name);
         Debug.Log("collide (start)(tag) : " + other.collider.gameObject.tag);

         Debug.Log("collide (shoot)(name) : " + player.instantiatedobj.name);
         Debug.Log("collide (shoot)(tag) : " + player.instantiatedobj.tag);

     }
     else 
     {
         Debug.Log("collide (start)(name) : " + other.collider.gameObject.name);
         Debug.Log("collide (start)(tag) : " + other.collider.gameObject.tag);

         Debug.Log("collide (shoot)(name) : " + player.instantiatedobj.name);
         Debug.Log("collide (shoot)(tag) : " + player.instantiatedobj.tag);

         player.instantiatedobj.GetComponent<PopBubble>().enabled = false;

     }
 }

}

image1.png (189.2 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 Malace · Aug 22, 2017 at 04:10 PM

From what I can see. I would have to guess that your bubble objects. Are likely already in a collision state from the start. Or get bumped into eachother after the first collision. IE: Your bubbles at the top already touch each other. Triggering OnCollisionEnter on all of them right from the get go. If you don't get the onslaught of debug.log until you fire then likely your shooting ball is bumping your objects into each other. Not sure at which point you screenshot was taken.

Few things could fix this. Either give them enough spacing to not bump colliders. Or go into your project settings and modify your 3d physics options. Set it so all of the target bubbles are in one layer that doesn't interact with itself. Then make sure your shooting ball is in a layer that does interact with the bubbles layer. Also you could check in your collision code if the collision was with another bubble, do nothing, else your shooting ball was the collision and delete both.

Best guess from what is here. Try your scripts in a scene with just one bubble. if your results are as you expect then likely you just need to make your bubbles not interact with each other.

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

Answer by Soos621 · Aug 22, 2017 at 03:05 PM

public class Test {

 PlayerController player;
 private Collider lastHitCollider;

 void Start() {
     GameObject playerobject = GameObject.FindWithTag("Player");
     player = playerobject.GetComponent<PlayerController>();
 }

 void OnCollisionEnter(Collision other) {
     if(other.collider.gameObject.name == player.instantiatedobj.name) {
         //Destroy(other.gameObject);
         //Destroy(player.instantiatedobj);
     } else {
         // save other
         if(!other.collider.Equals(lastHitCollider)){
             player.instantiatedobj.GetComponent<PopBubble>().enabled = false;
             lastHitCollider = other.collider;
         }
     }
 }

}

here i am just saving the collider and seeing if it has changed don't know if it will help or not though.

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

Answer by Hubinga · Aug 27, 2017 at 12:19 PM

Thank you guys! Your answers helped me a lot and now i can continue with my game :D

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

125 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

Related Questions

Unity2d move enemy in opposite direction on collision 1 Answer

Switch Scene on Collision with a Box 1 Answer

Can't change bool while accessing other script 2 Answers

Any one help me in this script? 0 Answers

Make the car stop by hitting the wall 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