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 G0DF4THER · Jun 08, 2019 at 05:50 AM · collisionrigidbody2dcollider2dbox collidertop down shooter

Collider wont collide. But I have done everything correctly.

So I'm pretty sure there is 0 reason for this to be happening but I'm making a top-down shooter and I have an enemy which has a box collider 2D attached to it and I have a projectile that has a circle collider 2D and a Kinematic Rigidbody attached to it. I have tried to add a mesh collider but that didn't seem to do much. I'm using the OnTriggerEnter2D function with the colliders set to 'Is Trigger' but the projectile just passes through the enemy and doesn't do anything at all. I have done everything correctly that I'm aware of but it just won't work. This code below is attached to my Enemy and it should destroy the enemy apon contact with the projectile but it dosnt :(.

  private void OnTriggerEnter2D(Collider2D other)
         { 
     if (other.CompareTag("Projectile"))
                 {
                     Destroy(gameObject);
                     Destroy(other.gameObject);
                 }
             }
 
 
 

Comment
Add comment · Show 2
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 SirPaddow · Jun 08, 2019 at 10:33 AM 0
Share

Did you attach a Rigidbody or a Rigibody2D?

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

How do you move your objects? Depending on what you do here there will be no collision detection.

1 Reply

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

Answer by JDelekto · Jun 08, 2019 at 10:59 AM

I would add a Debug.Log() in your OnTriggerEnter2D() to see if you are even getting in there and if you are, then log the tag of the object as well.

Make sure that the name of your tag and the tag "Projectile" are the same case. (i.e. upper-case 'P', the rest of the letters lower-case.

Aside from that, and it is not obvious from the code snippet itself, is to look at the layers that your objects are on and look at the physics layer interactions (Edit > Project Settings > Phyiscs 2D) to see if the interaction between them is un-checked.

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 BradyIrv · Jun 08, 2019 at 05:30 PM 0
Share

Also flip the two destroy statements because you don't want to destroy the enemy before you destroy the projectile. Otherwise you will most likely get an error (or nothing will happen to the projectile) since the enemy is destroyed before the code runs.

avatar image G0DF4THER BradyIrv · Jun 11, 2019 at 07:42 AM 0
Share

So I did all of this but in the end, it ended up being I had to put this part of the script onto the projectile script, changing the projectile tag and then it worked. Thanks for your help anyway, glad to finally get it working. :)

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

168 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 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

Location of RigidBody2D on collision 3 Answers

Object hits another but doesnt bounce off again. 0 Answers

set collision force after isKinematic disabled 0 Answers

I need help with Vectors, Positions, Rigidbody2d and Lerp. Please help me! 0 Answers

Rigidbody colliding with every section of floor 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