- Home /
Any way to prevent sweeptest from colliding their triggers?
My character has a trigger collider in front to detect obstacles to do auto jump. Due networking with authoritative server, I need to do sweeptests to detect collisions before ocurring.
The problem is, the sweeptest consider the triggers it contains as colliders, blocking the player movement. Is there a way to prevent this?
QueryTriggerInteraction.Ignore prevents sweeptests from triggering other triggers, but doesn't affect the triggers it has.
Sweeptests should not collide their triggers. Is there a way to prevent this? Is this a bug?
Answer by k76 · Mar 22, 2017 at 02:06 PM
Hey! Not sure if you already found a solution or not, but I've been trying to find a solution for hours and finally came up with something that works for me.
What I did was have the trigger on a child GameObject and (here's the important part) add a Rigidbody on the trigger GameObject. It seems like any settings will work on it too (e.g. isKinematic).
From my experience, as of Unity 5, SweepTest and SweepTestAll include all colliders on the rigidbody's GameObject and child GameObjects, regardless of layer or trigger status. HOWEVER, by having another Rigidbody on a child GameObject, it effectively excludes that from SweepTest calculations. Woo-hoo! =D
This is very important, because I was previously disabling the child trigger colliders prior to doing my SweepTestAll, but this causes a problem where OnTriggerExit is never called for these colliders, and the functionality simply does not work. With a single extra Rigidbody, all of my problems were solved!
Let me know if you get similar results. =}
Great! I was wondering how to tackle this problem, and although this solution might not be the best for performance, it certainly fixes the problem! Thanks.
Your answer
Follow this Question
Related Questions
How do you execute Trigger-collider collision only in one gameobject? 1 Answer
How to make work a collision when is invisible? 3 Answers
NPCs collide with collider but player does not 1 Answer
Prevent shooting when gun is inside wall 1 Answer
How to get collision point when using onTriggerEnter 5 Answers