Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kossad · Dec 14, 2012 at 10:09 PM · collisiononcollisionenterno errors

OnCollisionEnter - Simple line of hell

Hey!

I'v been searching and fighting with OnCollisionEnter for hours now and I simply cannot find the answer for this. Or I'v found hundreds of answers for this, but none of those work for me.

I'll try to keep this simple:

Here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class LittleThings : MonoBehaviour {
 
     
     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.name == ("Player"))
         {
             Debug.Log("test");
         }
     }
 }

If I understand right: With that code, I would be able to detect the collision of the Player object and the trigger object. But it does not work, I must miss something REALLY simple and stupid, but I cannot find it.

PS: There are no errors, nothing just happens!

Thank you for your help! :)

Comment
Add comment
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

4 Replies

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

Answer by MibZ · Dec 14, 2012 at 10:28 PM

If you're comparing against a trigger you want to use OnTriggerEnter, not OnCollision.

 OnTriggerEnter(Collider other)
 {
      if (other.gameObject.name == ("Player"))
             Debug.Log("test");
 }

You will also need to check the "isTrigger" checkbox on the collider of the trigger GameObject.

OnCollision is used to compare collision between two rigid bodies, like between the player and walls.

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
1

Answer by Kossad · Dec 15, 2012 at 01:18 AM

Yeah, I actually figured it out after a while! The problem indeed was that I was using OnCollisionEnter and I was supposed to use OnTriggerEnter. Changed that and ticked the "isTrigger" box in the inspector made it work just fine!

Thanks guys! :)

Comment
Add comment · Show 3 · 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 equalsequals · Dec 15, 2012 at 05:29 PM 0
Share

Please don't respond to answers with answers, but rather use comments like this. Also, make sure to upvote and check the answer that best helped so that others searching can easily find what they are looking for.

avatar image clunk47 · Dec 16, 2012 at 02:25 AM 0
Share

Yeah accept an answer or close the question so ppl know it's been answered :)

avatar image clunk47 · Dec 16, 2012 at 06:31 PM 0
Share

I voted you up for accepting an answer :)

avatar image
0

Answer by equalsequals · Dec 14, 2012 at 10:23 PM

Just a thought - because reading this made me think: You said player collide with trigger object. Is the collider the player is colliding with a trigger? Because if so you want OnTriggerEnter and not OnCollisionEnter.

Again - just a thought based on your wording.

==

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 alexpizzini · Dec 14, 2012 at 10:38 PM

Try

 void OnCollisionEnter(Collision collision)
 {
      Debug.Log(collision.transform.name);
 }
 

see what you 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

13 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

Related Questions

Collision with no contact? 2 Answers

Unparent object on collision? 3 Answers

onCollisionEnter function called from another object. 1 Answer

Change Direction on Collision 6 Answers

get angular velocity change from collision 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