Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 Tikasas · May 01, 2014 at 11:14 AM · collisioncollidercolliderstower-defense

object collision does not work

Hello, i am trying to make a simple tower defence game, and i have some problems with enemy and tower collision..

I have this Enemy script:

 void OnCollisionEnter(Collision collision) {
         Debug.Log (collision.gameObject.name); // never happens
         if(collision.gameObject.name=="col"){ 
             health--;
             print(health);
                 }
 }

And theres a box collider on the enemy aswell.

And then i have a tower object, with a child "col" that have a sphere collider.

Some Pics: https://www.dropbox.com/s/awwwtw8h45w2xo5/Screenshot%202014-05-01%2014.07.37.png https://www.dropbox.com/s/grrfnbcbesjsqfc/Screenshot%202014-05-01%2014.08.33.png

What am i doing wrong? Thank you in advance

P.S. also tried to add the sphere collider to the tower object, didn't work.

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

2 Replies

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

Answer by dovonobob · May 01, 2014 at 02:52 PM

from the manual:

"Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."

does either have a non-kinematic rigidbody?

Also if you're saying the debug.log never occurs then why don't you do a simpler bit of logging so you know 100% whether the collision is occuring or the problem is in one of the other lines in your collision code:

 Debug.Log ("ON COLLISION ENTER CALLED"); 

If that never gets logged then at least you know 100% that function isn't being called and it's a problem in your collider setup.

EDIT: having looked at your screenshots I can't see any rigidbodies attached so that's your problem I reckon.

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 Tikasas · May 01, 2014 at 03:15 PM 0
Share

ha! got to read the manual next time, lol. Thanks a lot! it is working fine now.

also used Sunrise$$anonymous$$ingdom advice to use OnTriggerEnter function. Thank you.

avatar image dovonobob · May 01, 2014 at 03:31 PM 0
Share

Got to love that manual ;)

No problem bud glad you got it working :)

avatar image SunriseKingdom · May 02, 2014 at 06:45 AM 0
Share

I'm happy you got it work.

avatar image
0

Answer by SunriseKingdom · May 01, 2014 at 11:35 AM

I would use

 function OnTriggerEnter (other : Collider)
 {
 
 }

On the enemy Collider make sure you Check on Is Trigger

Hope this help.

I also post videos online link text

Comment
Add comment · Show 1 · 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 Tikasas · May 01, 2014 at 11:47 AM 0
Share

well, i changed the code as you said:

 void OnTriggerEnter(Collider collision) {
         Debug.Log (collision.gameObject.name);
         if(collision.gameObject.name=="col"){ 
             health--;
             print(health);
         }
     }

also checked the isTriger box on, but still no progress

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

22 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

Related Questions

Is it possible to detect collisions between 2d and 3d objects? 2 Answers

Multiple Stacked Colliders only register for single object 0 Answers

Very complicated collider problems 0 Answers

How to get OnTriggerEnter effect without using isTriggered on Collider? 1 Answer

How to make two colliders or rigidbodies stick together upon collision, as if there was a glue on their surfaces? 3 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