Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 coolbird22 · Apr 03, 2014 at 09:27 PM · collisioncolliderdestroydetect

OnCollisionEnter2D is not detecting collisions.

I have a game object 'Crowd' that is instantiated in the scene multiple times. Each time it instantiates, it creates a clone called 'Crowd(Clone)' in the scene. I wish to destroy this game object each time it moves out of the scene bounds. For this, I created a blank game object and placed it outside the area where the camera cant see and I put a script on this game object to Destroy each copy of the instantiated object if it collides with this destroyer. The following is the script that I have attached to this destroyer.

 using UnityEngine;
 using System.Collections;
 
 public class SpawnKill : MonoBehaviour {
 
     private void OnCollisionEnter2D(Collision2D collision)
     {
         if (collision.gameObject.name == "Crowd(Clone)")
         {
             Debug.Log("Hit");
             Destroy(collision.gameObject);
         }
     }
 
 }

Both the game objects, 'Crowd' as well as the destroyer, have a Box Collider 2D components. I tried turning on the 'Is Trigger' checkbox, as well as rename the collision.gameObject.name from 'Crowd(Clone)' to 'Crowd' but it just wouldnt detect.

For some reason, the collisions are just not detecting and I don't know why. I'm using the 2D interface in Unity.

Any ideas anyone ?

Comment
Add comment · Show 12
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 robertbu · Apr 03, 2014 at 09:27 PM 0
Share

Are you moving your object using a Rigidbody2D script?

avatar image coolbird22 · Apr 03, 2014 at 09:34 PM 0
Share

No. I don't have RigidBody2D attached to either the game object nor the destroyer, the reason being, I'm working on a Top Down concept and RigidBody tends to add gravity and mass to it and makes it go into a freefall, which I dont quite require.

avatar image Infinite_Gamer · Apr 03, 2014 at 09:55 PM 1
Share

I would suggest using Tag rather than name...

I am "newer" to unity so I am not that experienced.

Hope this helps :D

avatar image coolbird22 · Apr 04, 2014 at 04:59 AM 0
Share

I already tried to assign a tag to the instantiated game objects and used that tag on the destroyer script but it yet does not detect the collisions oddly :(

avatar image Jun Hin · Apr 04, 2014 at 05:56 AM 0
Share

Have you tried using OnTriggerEnter ins$$anonymous$$d? $$anonymous$$ake sure the Is Trigger checkbox is on when you use this.

Show more comments

2 Replies

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

Answer by coolbird22 · Apr 04, 2014 at 08:03 AM

Adding a RigidBody2D was making the game object fall down. I just reduced the Mass to 0.0001, Angular Drag and Gravity Scale to 0 and it started working like I wanted it to. Awesome !!

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 haim96 · Apr 04, 2014 at 01:28 PM 1
Share

that what i meant by "disable gravity"... set it to 0.

avatar image
1

Answer by haim96 · Apr 04, 2014 at 08:14 AM

make sure you using 2d colliders also, you can use 2d rigidbody and disable gravity.

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

25 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

Related Questions

I created a ball and a wall object.How can i destroy the ball(player) in to particles upon collision with the wall? 0 Answers

Detect 2 colliders by trigger 1 Answer

Collision flag entering a tagged object's collider 2 Answers

Something wrong with destroying script 0 Answers

Help with destroying objects on collision 2 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