Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by TessellatingPi · Mar 01, 2015 at 10:12 PM · oncollisionenterontriggerenter2d

OnTriggerEnter2D & OnCollisionEnter2D not working

I have a problem with OnTriggerEnter2D & OnCollisionEnter2D. It does not seem to detect the collision and fire off the command. I am making a top-down space shooting game have added 2d colliders and rigidbody2ds to all my ships. However, even after reading different answers and adapting my code to be similar, it still will not work. The code for the player's ship is:

 using UnityEngine;
 using System.Collections;
 public class ControlScript : MonoBehaviour {
     public GameObject bullet;
     public GameObject bulletTwo;
     void Update () {
         rigidbody2D.velocity = new Vector2 (Input.GetAxis("Horizontal") * 10, rigidbody2D.velocity.y);
         if (Input.GetKeyDown (KeyCode.Space)) {
             Instantiate(bullet, new Vector3(transform.position.x - 0.5f, transform.position.y + 1.0f, transform.position.z), Quaternion.identity);
             Instantiate(bullet, new Vector3(transform.position.x + 0.5f, transform.position.y + 1.0f, transform.position.z), Quaternion.identity);
         }
     }
     void OnTriggerEnter2D (Collider2D other) {
         Debug.Log ("T");
         Destroy (gameObject);
     }
     void OnCollisionEnter2D (Collision2D other) {
         Debug.Log ("C");
         Destroy (gameObject);
     }
 }

The debug logging "c" & "t" is to see whether oncollisionenter2d is working or ontriggerenter2d. However, none of the log anything at all and don't destroy the player's ship. I have placed a box collider2d and rigidbody2d but still not working. Could someone please help? Thank you.

EDIT: The player's inspector window is as so: alt text

The bullet prefab's inspector window is like this:alt text

screen-shot-2015-03-02-at-45820-pm.png (61.5 kB)
screen-shot-2015-03-02-at-45901-pm.png (50.5 kB)
Comment
Add comment · Show 4
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 TessellatingPi · Mar 01, 2015 at 09:14 AM 0
Share

Oops, collider wasn't trigger and rigidbodies not kinematic, nut still not working. Scripts are definitely in place.

avatar image TessellatingPi · Mar 01, 2015 at 09:28 AM 0
Share

Even after editing, it's not working. Collision layer matrix is set so that the layer all the ships and bullets are on should interact with other objects on the layer.

avatar image meat5000 ♦ · Mar 01, 2015 at 12:51 PM 0
Share

Try saving the project and scene after using the matrix.

avatar image vvraja · May 06, 2021 at 07:04 PM 0
Share

Same issue here. Tried a lot of different things to no avail.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GSGregory · May 06, 2021 at 10:31 PM

I could be wrong, but I believe the bullet should have a collider as well.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnCollisionEnter2D being called twice sometimes 1 Answer

OnTriggerEnter2D works without being actually triggered. 0 Answers

destruction on impact 2 Answers

OnCollisionEnter not working with standard First Person Controller? 0 Answers

OnCollisionEnter as IEnumerator problem (WaitForSecond) 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