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 nug700 · Mar 19, 2015 at 03:03 AM · c#ontriggerenter

OnTriggerEnter not always triggering

For some reason when I fire a projectile (which has Trigger enabled) at my terrain (which is not a trigger) OnTriggerEnter is not being called every time the object hits it.

For example: https://www.dropbox.com/s/35pv4tyjvfc1svj/2015-03-17-2355-20.flv?dl=0

And here is the OnTriggerEnter function (located in the projectile script):

     void OnTriggerEnter(Collider other)
     {
         Debug.Log("enter " + other.gameObject.name);
         if (type == ProjectileType.Player && other.gameObject.tag == "Player")
             return;
 
         if (type == ProjectileType.NPC && other.gameObject.tag == "NPC")
             return;
 
         if (!exploded)
         {
             Debug.Log("explode " + other.gameObject.name);
             exploded = true;
             TerrainController.Instance.GenerateExplosion(rigidBody.position, explosionPower);
             GameObject audio = (GameObject)Instantiate(audioPrefab, rigidBody.position, Quaternion.identity);
             GameObject particalObj = (GameObject)Instantiate(partical, rigidBody.position, Quaternion.identity);
             audio.GetComponent<AudioSource>().Play();
             Destroy(particalObj, 5);
             Destroy(audio, 5);
             Destroy(gameObject);
             if (type == ProjectileType.Player && other.gameObject.tag == "NPC")
                 other.GetComponent<NPCControll>().Break();
         }
     }
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 alok-kr-029 · Mar 19, 2015 at 04:40 AM 0
Share

Just add rigidbody to the projectile it willl solve your problem

avatar image alok-kr-029 · Mar 19, 2015 at 05:16 AM 0
Share

then your terrain must be having mesh collider just check convex via inspector in the mesh collider and retry hope it will help

http://docs.unity3d.com/ScriptReference/$$anonymous$$eshCollider-convex.html

avatar image nug700 · Mar 19, 2015 at 05:20 AM 0
Share

The mesh collider for the terrain does not have "IsTrigger" Selected. Only the projectile does.

avatar image alok-kr-029 · Mar 19, 2015 at 05:44 AM 0
Share

I mean you dont have to select the trigger of mesh just check the convex terrain -> mesh collider -> convex set true . in inspector

avatar image nug700 · Mar 19, 2015 at 05:52 AM 0
Share

That would make the collider not match the actual terrain because it would be convex, and thus a different shape.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Subhajit-Nath · Mar 19, 2015 at 04:29 AM

There are two possibilities I can think of right now.

  1. You are missing an active rigidbody in the projectile.

  2. The velocity of the projectile is too high for collision detection. You will need to change the collision detection mode in the rigidbody to continuous and make the triggers and colliders much more bigger.

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 nug700 · Mar 19, 2015 at 04:52 AM 0
Share

It already had a rigidbody, and setting the collision detection to continuous helped a little but didn't solve it completely. It's also strange, because When I shoot a projectile that goes right through, and then shoot more without moving the mouse, they also go right through. As soon as I move the mouse just a little (almost as if there are holes in the collider, however none show up when I disabled the mesh renderer to view the collider mesh), it interacts with the terrain again.

avatar image Siraaaj-Ahmed · Dec 19, 2016 at 09:37 PM 0
Share

Nice one, I got a similar problem and pretty sure its due to my objects velocity being too high. Trying to find a way around it without lowering the velocity.

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

23 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

GameObject tag to if condition 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

OnTriggerEnter On seperate object (than the script is attached to) 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