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 Noxwill · Jan 01, 2014 at 03:46 AM · collisionontriggerenterlayersbox colliderontriggerexit

[SOLVED] OnTriggerExit only called when object moves

I have my Player and Enemy objects on the same layer and I made them ignore collision with each other.

 Physics.IgnoreLayerCollision(8,8, true);

My Enemy object has a Child that is on the Default layer, and I'm using a Collider on that object to detect when my Enemy collides with a Player (the Child object just has a Box Collider that is set right in front of the Enemy object)

The OnTriggerExit is being called properly when the Player moves out of the Enemy's Child Box Collider, but NOT when the Player remains standing still and the Enemy is the one that moves away (thus its Child collider moves away with it)

My OnTriggerEnter suffers from this because it doesn't detect another Enter if the last Exit wasn't called so... it's screwing up all the collision detection.

Is it because the parent object is on a layer that is ignoring collision that the child object is being affected this way? Either way, how do I fix this?

EDIT: I also Debug.Logged to make sure it was happening the way I explained. It will only call when Player object moves out of the collider, but not when the collider moves away from the player who is standing still.

EDIT2: I have a feeling it's because both Player and Enemy are ignoring collisions, and even if there's a Child object that's on another layer that accepts collisions, the physics engine doesn't respond well to it. I'll test this tomorrow and update.

EDIT3: Found the solution! It's because the Child Box Collider is 'sleeping' and must have a Kinematic Rigidbody attached in order to 'wake up' and calculate collisions continuously.

Unity docs on Rigidbody sleeping

This tells you:

If you have a sleeping rigidbody and you move a static collider (A collider without a Rigidbody attached) into the rigidbody or pull it from underneath the rigidbody, the sleeping rigidbody will not awake. So if you have a lot of Static Colliders that you want to move around and have different objects fall on them correctly, use Kinematic Rigidbody Colliders.

So basically if you want to calculate collisions with static colliders (normal capsule, sphere, box, etc) and want them to move around a lot then make sure to attach a Rigidbody and check 'Is Kinematic'

Comment
Add comment · Show 1
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 sparkzbarca · Jan 01, 2014 at 09:50 AM 0
Share

it can also be that your issue is with whats colliding with what

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

use the little chart at the bottom to make sure yoru doing it right. It sounds to me like the actual problem is your player or object is "sleeping" and so it doesnt register collision, thats a thing the physics engine does automagically to keep calculations down, but in order for stuff to be woken it needs to move or something or have rigidbodies and stuff.

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

Why would OnTriggerEnter get called, but not OnTriggerExit? 0 Answers

Problem with OnTriggerExit 1 Answer

Do OnTrigger functions have to check all objects in the trigger per frame? 1 Answer

Weird OnTriggerEnter / Exit behavior 1 Answer

OnTriggerExit doesn't work when scaling collider 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