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 /
  • 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.

avatar image Falconeyi aditya007 · Nov 22, 2016 at 05:34 AM 0
Share

Yeah, I tried those changes. I must have forgotten the tags when I was messing around with it. The problem persists. Nothing happens...

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.

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

What is the 3D equivalent of using Physics2D.OverlapArea to check for if a character is grounded? 2 Answers

2D Platformer Character Acts Weird When Collide Side of a Platform 0 Answers

App works fine on PC but not on android 0 Answers

Raycast doesn't work properly 1 Answer


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