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
2
Question by sethi-sahil27 · Apr 10, 2016 at 09:36 AM · c#prefabontriggerenternot workingoncollisionenter

OnCollisionEnter() not getting called between two rigid bodies

 void OnCollisionEnter(Collision other)
     {
                 print("Called");
         if(other.transform.tag=="enemy")
         {
         //die();
         print ("enemy hit");
         }
     }


i'm very new to Unity,basically building my first game. in my game i have a PreFab(enemy) , that gets created N number of times and is a sphere . i have another sphere, the main character, which when collides with the enemy/s, it should destroy that enemy, but the OnCollisionEnter() does not get called. and both of them are in motion, the player is in circular motion and the enemy in a staright line towards the centre of the circle around which the player revolves. details about prefab and player

PreFab(enemy): sphere, sphere collider,rigidbody player: sphere, sphere collider,rigidbody

any suggestions would be helpful.

Thanks

Comment
Add comment · Show 9
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 Oribow · Apr 10, 2016 at 09:50 PM 0
Share

Are you moving the rigidbodys with forces?

avatar image nullgarden · May 19, 2017 at 03:45 AM 0
Share

I'm having the same problem. Both GameObjects have rigidbodies. Other suggestions on this form haven't been very helpful. In addition both my GameObjects are non-kinematic and have box colliders with isTrigger enabled. I've double checked my physics settings and everything in the Layer Collision $$anonymous$$atrix seems to be enabled..

avatar image tanoshimi nullgarden · May 19, 2017 at 06:36 AM 0
Share

@leftoversalad "In addition both my GameObjects are non-kinematic and have box colliders with isTrigger enabled."

That'll be why then: if you want objects to collide, you want them NOT to be triggers...

avatar image tanoshimi nullgarden · May 19, 2017 at 09:36 PM 0
Share

we'd probably need to see your code...

avatar image Clem46 · May 19, 2017 at 12:03 PM 0
Share

Hi, check on your two rigidbody you have a physics collider. Try with is trigger on and is trigger off

avatar image tanoshimi Clem46 · May 19, 2017 at 12:24 PM 0
Share

There's no "trying" involved: if you want OnCollisionXXX to fire, you turn triggers off.

avatar image nullgarden Clem46 · May 19, 2017 at 08:44 PM 0
Share

@tanoshimi @Clem46 even with all triggers off OnCollisionEnter() is not executing

avatar image nullgarden nullgarden · May 19, 2017 at 08:52 PM 0
Share

Could it be that I'm missing a component? Here are my game objects:

Name: Bullet

Components:

Sprite Renderer;

C# script (bullet control);

Rigidbody {mass:1, drag:0, angular drag:0.05, useGravity: false, is$$anonymous$$inematic: false, interpolate:none, Collision detection: discrete, constraints: freeze all rotations};

Box Collider {isTrigger:false, material: none, center:(0,0,0), size:(1,1,1)}

====

Name: Player

Components:

Sprite Renderer;

C# script (player control, contains OnCollisionEnter);

Rigidbody {mass:1, drag:0, angular drag:0.05, useGravity: false, is$$anonymous$$inematic: false, interpolate:none, Collision detection: discrete, constraints: freeze all rotations};

Box Collider {isTrigger:false, material: none, center:(0,0,0), size:(1,1,1)}

Show more comments

3 Replies

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

Answer by SwissCore · May 19, 2017 at 11:37 AM

try: if (other.CompareTag("enemy")) Or are you sure your tag is "enemy" not "Enemy"? Maybe its only a little typo. :)

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 Endi24 · May 20, 2017 at 01:26 PM

It may be that the tag you are looking for is "Enemy" or that you don't actually need the transform, just other.CompateTag("Enemy").

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 nullgarden · May 20, 2017 at 07:12 PM

I finally got mine to work by changing other.gameObject.tag == "Enemy" to access the collider: other.collider.gameObject.tag == "Enemy":

 void OnCollisionEnter(Collision other){
 
         if(other.collider.gameObject.tag == "Enemy"){
                          print("hit");
             }
     }

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

10 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

Related Questions

Distribute terrain in zones 3 Answers

On Trigger Enter, Collide with object, specific collision 1 Answer

Nav Mesh Agent para perseguir a un clon 1 Answer

Checking Tag of Trigger Prefab 1 Answer

OnTriggerEnter/OnCollisionEnter and 5.0 3 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