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
0
Question by rct3fan24 · Nov 10, 2013 at 07:50 AM · collisiononcollisionenter

WHY WON'T YOU DIE?! (Why won't the OnCollisionEnter function run?)

Hi, I have a problem. See, I'm trying to make it so that when you fall in water, you die. (I don't have Unity Pro, so I'm just using the simple water thing, adding an object under it.) Here's the script I have:

 function OnCollisionEnter(death:Collision)
 {
     Debug.Log("Collide with thing");
     
     if(death.gameObject.tag == "Enemy")
     {
         Debug.Log("DIE");
         Application.LoadLevel("dead");
     }
 }

Does anyone know what the problem is, and how to fix it? The object DOES have the Enemy tag. Also, this script does work with other things, like the enemies that run towards you.

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 Fornoreason1000 · Nov 10, 2013 at 07:58 AM 0
Share

does "Collide with thing" run?

does the water itself have collider by accident?

does the object with the enemy-tag have Is trigger UNchecked?

Is Enemy tag Spelled correctly(copy and paste it)

(trust me it can really fool you around)

avatar image rct3fan24 · Nov 10, 2013 at 08:04 AM 0
Share

I've checked and rechecked everything on that list. I'm so confuuuuuused!

Oh, and no, "Collide with thing" doesn't run.

avatar image meat5000 ♦ · Nov 10, 2013 at 08:48 AM 0
Share

Using character controller? Any rigidbodies involved?

avatar image fafase · Nov 10, 2013 at 08:48 AM 2
Share

Where is this script attached? Is the water trigger? Does your guy have a rigidbody, even is$$anonymous$$inematic?

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rodude123 · Nov 10, 2013 at 08:45 AM

Try this example

 function OnTriggerEnter (other : Collider) {
     Debug.Log("Collide with thing");
     if(death.gameObject.tag == "Enemy") {
         Debug.Log("DIE");       
         Application.LoadLevel("dead");    
     }
 }

this should help this is in JS

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 aldonaletto · Nov 10, 2013 at 09:54 AM 0
Share

For this to work, the water plane must be a trigger and must have this script attached, and the character must be a CharacterController or a rigidbody.

avatar image sdgd · Nov 10, 2013 at 11:30 AM 0
Share

what about OnControllerColliderHit ?

afaik controller and OnTriggerEnter don't work well together

avatar image
0

Answer by Aspirer · Nov 10, 2013 at 09:42 AM

Most likely, your player's collider's "Is Trigger" is checked, for the sake of other functions in your game. When IsTrigger is checked, none of the OnCollision functions are called--instead, "OnTriggerEnter", "OnTriggerStay" and "OnTriggerExit" are called.

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 hamstar · Nov 10, 2013 at 11:07 AM

If your "death" object uses a mesh collider, you may need to set convex to true in the Mesh Collider inspector settings.

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 ZDS Alpha · Nov 10, 2013 at 11:10 AM

You are using FPS Character Control. Am I right? Look this:

http://answers.unity3d.com/questions/571448/oncollisionenter-is-not-working-1.html

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

24 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

Related Questions

Collision with no contact? 2 Answers

Unparent object on collision? 3 Answers

Transform collider not detecting collision on rigidbody collider 2 Answers

onCollisionEnter function called from another object. 1 Answer

Change Direction on Collision 6 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