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 BenJohnston · Apr 22, 2012 at 02:50 AM · collisiondamage

OnCollision Enter stopped working Please help

Hi , I had a script working fine for shooting rockets at an enemy and doing damage based on the enemy. For some reason now though it has stopped working and i cant figure out why

Rocket prefab has rigid body and mesh collider Enemy has Rigidbody and character controller

here is the code i have...print isnt triggering

 var explosion : GameObject;
 
 function OnCollisionEnter(myCol: Collision)
 {
     var contact : ContactPoint = myCol.contacts[0];
     var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal ); // Ensure Explosion follow science!
      var instantiatedExplosion : GameObject = Instantiate(explosion, contact.point, rotation );
      
     print("Hit something");
      
       
   if(myCol.gameObject.name == "Enemy")
       { 
     myCol.gameObject.SendMessage("ApplyDamage", 10, SendMessageOptions.DontRequireReceiver);
       }
       
         Destroy(gameObject);
 
 }

  

Any help greatly appreciated

Comment
Add comment · Show 5
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 AchillesWF · Apr 22, 2012 at 03:11 AM 0
Share

You probably have disabled or lost the collision volume associated with the object.

avatar image BenJohnston · Apr 22, 2012 at 03:12 AM 0
Share

I have no idea what that means :)

avatar image AchillesWF · Apr 22, 2012 at 03:32 AM 0
Share

GameObjects need an attached physics object to receive the OnCollision() calls.

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

You'll want to make sure the collider is active for the Rocket and the Enemy so that they can actually collide.

avatar image BenJohnston · Apr 22, 2012 at 07:01 AM 0
Share

everything appears active on the rocket and the enemy =/

avatar image BenJohnston · Apr 22, 2012 at 07:02 AM 0
Share

Rocket has mesh collider and enemy has character controller

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Apr 22, 2012 at 09:50 AM

Would it have stopped working after you added or altered the CC?

Try to set the rigidbody of the enemy to IsKinematic.

That will disable the collision of the rigidbody. At the moment I would think you have collision detected for the CC and the rigidbody.

I had a similar answer 3 days ago and I fixed the issue as such:

"I made a simplified version, I have a sphere which act as your bullet, it has rigidbody, sphere collider (no IsTrigger) and just a movement script. Then i have another sphere that acts as your enemy with CC, rigidbody (IsKinematic) and a sphere collider (no IsTrigger).

It has only this script:

  var lives = 5;
     function OnCollisionEnter(other:Collision){
         if(other.gameObject.tag =="Sphere")   
            Debug.Log("Collision");
            lives-=1;} 

And it works. I have not altered any other members of it all, just add components and that is it. MAybe you could add a collider to your enemy. As you rigidbody is set to IsKinematic, it won't interfere as IsKinematic disables the collider."

here is the original question http://answers.unity3d.com/questions/241963/enemy-not-getting-hit-collider-issue.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
avatar image
0

Answer by BenJohnston · Apr 22, 2012 at 03:47 PM

Even removing the CC and adding a Sphere collider its the same issue.

I tried adding IsKinematic but still no love

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 fafase · Apr 22, 2012 at 05:07 PM 0
Share

You could try to remove the prefab and place it agina, maybe something went broken at some point and your prefab lost a connection somewhere. By doing it again, if your original prefab is fine, it should work again.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How Can One Collider Recognize Contact With Another? 0 Answers

Damage with collision force? 0 Answers

Base mesh deformation into secondary mesh with collisions. 1 Answer

Car Collision Damage 1 Answer

Cannot detection collision 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