• 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 Falconeyi · Nov 22, 2016 at 03:33 AM · collision detectionprefab-instance

Collision detection problem between prefab and gameobject

I can't wrap my head around this problem. I've tried adding onCollisionEnter and onTriggerEnter on both my cube and my bullet prefab but neither of them detects a collision between them. I've searched on google on this problem but couldn't find a solution that worked.

This is my script on my cube gameobject.

 using UnityEngine;
 using System.Collections;
 
 public class testcollision : MonoBehaviour {
 
     public GameObject bullet;
 
     void onTriggerEnter(Collider other) {
         if(other.gameObject.tag == "bullet" ) {
             Destroy(this.gameObject);
         }
     }
 
     void update() {
         
     }
 }

This is the inspector menu on the cube gameobject: http://i.imgur.com/M0WDZIX.png

This is how my bullet is being made. It gets shot from my player character.

 using UnityEngine;
 using System.Collections;
 
 public class AutoattackBULLET : MonoBehaviour {
 
     public GameObject Bullet_Emitter;
 
     public GameObject Bullet;
 
     public float Bullet_Foward_Force;
 
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if(Input.GetKeyDown("a")) {
             GameObject Temp_bullet_handler;
             Temp_bullet_handler = Instantiate (Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
 
             Temp_bullet_handler.transform.Rotate(Vector3.left * 90);
 
             Rigidbody Temp_Rigidbody;
             Temp_Rigidbody = Temp_bullet_handler.GetComponent<Rigidbody>();
 
             Temp_Rigidbody.AddForce(transform.right * Bullet_Foward_Force); //use transform.right
 
             Destroy(Temp_bullet_handler, 0.4f);
         }
     
     }
 }

This is the bullet prefab's inspector menu: http://i.imgur.com/sFiAlZU.png

The bullet does bounce off the cube but I can't get a collision check anywhere.

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 aditya007 · Nov 22, 2016 at 05:10 AM 0
Share

OnTriggerEnter will never be called, because none of your objects is a "Trigger", use OnCollisionEnter ins$$anonymous$$d. And, why you have the same tag "bullet" on both gameobjects ,i.e., Bullet prefab and cube?. Try changing the tag of Cube and see if it works.

Show more comments

1 Reply

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

Answer by romatallinn · Nov 22, 2016 at 05:49 AM

It is important to have OnTriggerEnter, but not onTriggerEnter (capital O is needed).

Comment
Add comment · Show 4 · 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 Falconeyi · Nov 22, 2016 at 07:18 AM 0
Share

If I use OntriggerEnter, what settings would I need to change?

avatar image aditya007 Falconeyi · Nov 22, 2016 at 07:28 AM 0
Share

Enable "Is Trigger" in the Collider component of 1 of the GameObject.

avatar image Falconeyi aditya007 · Nov 22, 2016 at 08:35 AM 0
Share

Thanks guys. I can't believe that I spent hours just because of a capital O....

avatar image romatallinn Falconeyi · Nov 22, 2016 at 08:35 AM 0
Share

Again, it is important to use correct spelling - OnTriggerEnter. :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

78 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

Related Questions

Detecting collisions between instantiated prefabs? 0 Answers

Which of Mulitipe colliders OnCollisionEnter ? 0 Answers

Evading obstacles 0 Answers

Trouble with detecting collision in the same frame to make smart labels 0 Answers

Collisions problem in VR 0 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