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 /
avatar image
0
Question by Henri 1 · Jul 07, 2011 at 07:52 PM · collisionrigidbodycollideroncollisionentersendmessage

Cannot get collision to do anything

Good day fellow Uniters!

Haven't used Unity since April, so I'm again confusing myself.

For some reason, I cannot get Collision to work :?

Script attached to my Cube (Which the player needs to walk into in order to test my Awesomely simple health script) as follow:

 function OnCollisionEnter(collision : Collision) {
     if(collision.rigidbody){ 
        gameObject.FindWithTag("Player").SendMessage("ApplyDamage");
        print ("Hit!");
     }


And on the receiving side (Player) the following:

 function ApplyDamage () {
 Debug.Log("Hit!");
 }

And VIOLA! Nothing happens :(

I have RigidBodies attached to both the Cube and the Player, Cube also has a Box Collider.

If any Einstein replica's are willing to ease my pain, I bake quite lekker cookies (Shipping Excluded) :)

Thanks!

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 Dreamblur · Jul 07, 2011 at 08:14 PM 0
Share

Does the player have a collider?

avatar image Henri 1 · Jul 08, 2011 at 09:16 AM 0
Share

Hi Dreamblur, the player has no specific collider (such as mesh or box collider) but it does have a ThirdPersonController script which basically has a capsule collider. Everything in my scene works 100%, player can walk, jump, fly, run shoot beams, powerup etc, just the darn collision doesnt work. If you browse my previous questions, you will notice that I have struggled before with sending messages, but at that time my collision worked 100%. Now I deleted the script, cant find it in my backups and couldn't remember exactly what I need to do :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Grady · Jul 08, 2011 at 10:18 AM

make sure you have a collider on both, and that one has a non kinematic rigidbody....

If that still doesn't work, then try this script

 function OnCollisionEnter(collision : Collision){
     if (collision.gameObject.tag == "Player"){
         gameObject.FindWithTag("Player").SendMessage("ApplyDamage");
     print("Hit!");
     }
 }

alternatively, you can try this:

 var collisionObject : GameObject;
 
 function OnCollisionEnter(collision : Collision){
         if (collision.gameObject == collisionObject){
             gameObject.FindWithTag("Player").SendMessage("ApplyDamage");
         print("Hit!");
         }
     }

Hope this helps....

If you need more help, then comment back...

-Grady

Comment
Add comment · Show 5 · 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 Henri 1 · Jul 09, 2011 at 02:20 PM 0
Share

Hi @Grady.

I keep getting the error message "Script error: OnCollisionEnter This message parameter has to be of type: Collision The message will be ignored."

No matter what I try... Previously I have not received this error and no matter what I do, as soon as I click play, the error occurs. I do not have any other collision functions in my scene... Any Ideas?

avatar image Henri 1 · Jul 09, 2011 at 02:38 PM 0
Share

Hi @Grady,

I renamed my script and it seems to eli$$anonymous$$ate the error, but it still wont collide... I created a new scene, added some scripts and the collision did register, but it seems as if something in the script aint right, as it does register collision, but not with the script specified (collision.gameObject.tag == "Player"). I did try multiple other ways, but still not working :(

avatar image Grady · Jul 11, 2011 at 08:24 AM 0
Share

make sure that both objects have colliders, one has rigidbody that is non kinematic, and make sure that the object that you are attaching this script to is not tagged "Player". The object that you want to collide with has to be tagged "Player".

So in other words, the other object that does not have this script on it must be tagged "Player"

I've also edited my answer above so you can try a different method...

-Grady

avatar image Henri 1 · Dec 13, 2011 at 09:21 PM 0
Share

Hi @Grady,

So long since I replied. Sorry that I havent chose your answer as "Best Answer", but I ended up using "OnControllerColliderHit" which worked, but for some reason slowed down my audio playback everytime I use one of my player's powers. Thanks again for your help. Again I'm strugling with my collisions, just posted a question. $$anonymous$$aybe you can check it out? Adios

avatar image Grady · Dec 14, 2011 at 11:12 AM 1
Share

O$$anonymous$$, glad I could be of some help!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer

Which Object Calls OnCollisionEnter()? 3 Answers

Collision Only being detected on one of the objects involved in the collision - C# 0 Answers

Why OnCollisionEnter cannot detect collisions between colliders? 1 Answer

simple onCollision and onTrigger problem 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