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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by AdamWaters · Sep 17, 2012 at 08:47 AM · collision detectiontriggers

Collision Detection Randomly Ignores Hits

The Problem:

I Instantiate special affects & projectiles that use a collider to detect whether it has hit a unit. If it hits the unit it does damage. Units are not being hit by the special affects despite the fact that they are clearly within it's collider. Units that are more recently created have a higher chance to ignore the collision.

Video

http://www.youtube.com/watch?v=EJAWFzkJ5XY&feature=plcp

The Details:

The units have Rigid Bodies, and they are detected about 30% of the time. When paused it is clear that the colliders overlap. The collision is detected by using the OnEnter Trigger. I have also tried On Stay, and the only change is that when it actually detects a collision it triggers every frame instead of once(As it should), but still detects nothing more often.
It seems that the chance of a collision being detected is increased if the Unit has moved or been acted upon in some way. (Such as moving to a new location) I have tried increasing the Collision Detection field on the Rigid Body. No matter the setting, the results don't seem to change.

The code for this is very standard. I check send the collider to another function which deals the damage or spawns effects. The _Attacker is the attacking unit and _EffectAttack & _SpecialAttack are classes that contain the amount of damage or effect to spawn. The code does not even hit the Debug lines which tells me that it is flat out not colliding.

 void OnTriggerEnter (Collider collisionObject) 
 {
     Debug.Log("Attacker: " + _Attacker);
     Debug.Log("Hit: " + collisionObject.gameObject);
         
     if(_EffectAttack != null)
         InitiateAttack(_EffectAttack,  collisionObject.gameObject);
     else if(_SpecialAttack != null)
         InitiateAttack(_SpecialAttack,  collisionObject.gameObject);
 }

I updated to the latest version of unity a few days before I noticed the issue, so I'm thinking it might be a bug in Unity, but I'm not sure.

Could the problem be associated with using an Instantiated Collider to detect an Instantiated Rigid Body?

Has anyone else experienced similar issues and what steps were taken to fix it?

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 Khada · Sep 17, 2012 at 09:02 AM 0
Share

Does it happen if you don't use trigger colliders? Are you using continuous or discrete collision? I remember a bug where continuous collision objects were not calling OnCollisionEnter properly though I am not sure whether or not that problem was fixed.

avatar image Zerot · Sep 17, 2012 at 10:15 AM 0
Share

The video link you have in the question is broken. (it is a shortened link with ... in it, ins$$anonymous$$d of a proper link)

avatar image AdamWaters · Sep 17, 2012 at 02:08 PM 0
Share

I have fixed the video link. I have tried changing their detection between all 3 options with no change. Right now they are all set to discrete.

avatar image Khada · Sep 17, 2012 at 02:16 PM 0
Share

Hmm, that does look odd. It could be any number of things. For now, a work around might be to use Physics.OverlapSphere which would give you the same functionality via different means. Here is an example:

 Collider[] colliders = Physics.OverlapSphere(transform.position, 10);
             
 for(int i = 0; i < colliders.Length; ++i)
 {
     if(colliders[i].rigidbody != null)
             //do stuff to object
 }

Could you let me know if that works? If not, I would seriously lean towards the issue being a unity bug.

avatar image AdamWaters · Sep 17, 2012 at 02:28 PM 0
Share

$$anonymous$$y scripts that use Physics.Overlap haven't had any problems. In the video you can see it working when I double click a unit to select all of them. That script is similar to yours, except I don't check for a rigid body. I can add that in tonight.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · Sep 17, 2012 at 04:41 PM

Attach a rigidbody to the thing with the sphere collider and it will wake up the units presuming it is itself awake. See here for details.

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 whydoidoit · Sep 17, 2012 at 08:40 PM 0
Share

You could also set the rigidbody sleep velocity on the thing with the sphere collider to 0 so that it never sleeps.

avatar image AdamWaters · Sep 18, 2012 at 02:57 PM 0
Share

After reading more about the sleeping colliders and how rigid bodies interact with them I've used $$anonymous$$inematic rigid bodies to interact with the units. Now the colliders now wake up the units and everything works great.

avatar image
0

Answer by Zerot · Sep 17, 2012 at 10:48 AM

The problem is that you instantiate a collider/trigger. This is not a problem per se, but colliders(especially sleeping ones) that are in its range will not trigger any of the events until they are moved/woken up. And even then the enter might not fire because they are already in the collider, not entering it.

Now, for a proper solution you shouldn't do the check by creating a collider, but by using one of the various checks that physx provides. For example: http://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html

Comment
Add comment · Show 7 · 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 AdamWaters · Sep 17, 2012 at 02:16 PM 0
Share

Is there a way to "wake up" a sleeping collider? I can't seem to find anything about this other than changing the detection setting so that the rigid body checks more often.

I have also tried changing the triggers to OnStay and found that the same issue presents itself; Some objects just seem to be completely ignored.

In places where I use OverlapSphere it has worked without problems, but I don't think OverlapSphere should completely replace all of my Collision triggers. It's nice to have a fall back plan, but removing all of my Colliders is not my preferred fix.

avatar image Khada · Sep 17, 2012 at 02:22 PM 0
Share

I didn't see that zerot has proposed using OverlapSphere (apologies). You would only be removing colliders from the aoe-skill-effect-prefab. All your unity would need to retain their colliders either way.

avatar image Zerot · Sep 17, 2012 at 02:23 PM 0
Share

Yes, you can wake up rigidbodies using http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.WakeUp.html

But why do you want to use colliders? the whole instantiating them, waking up rigidbodies, etc. are really expensive operations that are not guaranteed to work properly the way you are using them. overlapsphere however, is a quite cheap solution that is guaranteed to work.

avatar image AdamWaters · Sep 17, 2012 at 02:37 PM 0
Share

I just want to be aware of all my options, I'm not shooting anything down right now at all; and I'm very grateful for all the help you guys are giving.

Projectiles that use Colliders are also affected. How does calling Overlap Sphere on update or through a repeated function stack up performance wise?

avatar image Khada · Sep 17, 2012 at 02:47 PM 0
Share

You can give the OverlapSphere a layer argument to ensure you're only checking against the appropriate objects etc. Sphere collision is as cheap as it gets and it's what you're doing with the current system anyway. I wouldn't expect to see any noticeable chance in performance, though the profiler could prove me wrong.

Show more comments

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

13 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

Related Questions

Enable panel in Canvas when Trigger Collids 0 Answers

2D - Two objects, each having two trigger colliders - interacting 0 Answers

Enemy not going up during attack animation 1 Answer

Audio trigger when FPS walks into things, walls, doors etc 0 Answers

Collisions without rigidbody.MovePosition 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