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 ShankaP · Feb 22, 2014 at 01:03 AM · collisionontriggerenterimpact

Unable to get OnTriggerEnter to work.[JS]

This is my first game I've tried to make so bear with me.

My goal is to call OnCollisionEnter when two objects collide: my player ship(which it might be worth mentioning is a three part object cointained under a parent object) and an asteroid.

My script_player method goes:

 function OnTriggerEnter (other : Collider) { 
 
     if (other.gameObject.tag == "Asteroid") { 
         print("Collision!");
     }
 
 }

Both my player and asteroids have rigid bodies attached and isTrigger is true. Both of the settings are identical with the exception of the ''Mesh'' field where the asteroids have a mesh instead of ''None''. Also note that the rigid body has been applied to both the parent and the children. I've also added colliders to each piece.

These are the settings for EVERY piece. They are identical except for what is contained in the ''Mesh'' section.

alt text

So finally, the problem is that OnCollisionEnter will not call! I have it in a separate script with objects set up the same way. The only difference is the object itself. It is a bullet which is simply a scaled down sphere.

Here is that code:

 function OnTriggerEnter (other : Collider) { 
 
     if (other.gameObject.tag == "Asteroid") { 
         var otherObject = other.GetComponent(script_asteroid); 
         if (otherObject.health <= 0) { 
             Explosion(); 
             AddPoints(otherObject.points); 
             otherObject.Spawn(); 
         }
         if (otherObject.health > 0) { 
             otherObject.health--; 
         }
         Destroy(gameObject); 
     }
 
 }

This code works fine when the bullet hits the asteroids, but I can't get the same function when one hits the ship.

I've tried adding colliders and rigid bodies to every part of the ship, copy/pasting code(minus a few bits) but I can't figure out what I'm doing wrong. I've also looked through many other answers to questions similar to this. I'm hoping I'm missing something simple.

Thanks for any help.

screenshot_1.png (17.0 kB)
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
1
Best Answer

Answer by Linus · Feb 22, 2014 at 07:45 PM

I think the problem is with 2 mesh colliers with rigid body.

See the table at the bottom of this page.

http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html

Either use sphere collider, or another basic collider on one object, or check the convex box on the collider component.

Another possibility is that they are not aligned on one axis, this can often happen if you are making a 2D game in 3D.

  • up vote for making detailed question, and showing that thought went into making the best question possible. Even though the question has been asked a million times, and solution can be found rather easy on the internet.

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 ShankaP · Feb 23, 2014 at 05:09 AM 0
Share

Ended up using a basic collider. That was the solution. Thank you for the suggestion.

avatar image
1

Answer by haim96 · Feb 22, 2014 at 07:38 PM

did you remembered to set the correct TAG for the ship? keep in mind that tags are case-sensitive.

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

20 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

Related Questions

OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers

OnTriggerEnter function giving mixed results 1 Answer

Multiple collisions not working.Plz help 0 Answers

Playing a sound proportionally to the force of an impact, via C# script 1 Answer

Shooting myself 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