- Home /
How can I get multiple objects with triggers, and standard collisions to work together?
I have four objects: Player (Box Collider with trigger disabled), Bullet (same as player), a ball (Sphere collider with trigger on), and a goal (Mesh Collider with trigger disabled).
I need the player to be able to trigger a ball pickup, and the ball to collide with the goal (say the player shoots the ball from an odd angle, and misses the hole), and I need the bullets to collide with the player and cause them to spin out.
I can get the bullets, players, and balls to interact properly. But, I can't seem to find the right combination to make the ball collide with the goal, and bounce off.
The strange thing is, I had all four of these objects working perfectly as they should, but somewhere along the path, I broke these things somehow.
If I turn the player into a trigger, then the ball into a non-trigger, then bullets go through the player without collision, yet the ball will bounce off the goals.
Any ideas would be appreciated.
Answer by XaeroDegreaz · Jul 21, 2012 at 07:33 AM
I did not resolve this by messing with the triggers, however I opted to add a second Collider to the ball. The first Collider has the trigger turned off, and collides only with the goals, thanks to the physics matrix in the preferences. The second Collider, with a trigger, is a child GameObject of the ball, and triggers when players touch it.
Answer by Seth-Bergman · Jul 21, 2012 at 06:38 AM
Since the ball is a trigger, you should be able to add the code to the balls OnTriggerEnter function.
if(collider.tag == "goal") //etc...
If you wanted actual physics, you could turn trigger off during a shot, that should allow normal collision detection
something like:
if(isShot)
collider.isTrigger = false;
else
collider.isTrigger = true;
EDIT:
another option is to add an empty child object to the ball, and make THAT the trigger
Finally, for the full picture, go to this link, and scroll down to the bottom:
http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
the collision matrix there will answer your exact questions..
Thanks for the input. I did think of this, however the ball also needs to be passed from player to player, and with the trigger turned off, the ball would bounce off of players.
if you want it to have physics, you don't really need the trigger.. just use OnCollisionEnter for everything..
if that's not desired, see the first suggestion above edit: or the third..
Your answer
Follow this Question
Related Questions
How to have multiple colliders intersect without colliding with each other? 1 Answer
[Unity 4.6.1] Weird bug between 2 Colliders 1 Answer
Can I make a collider ignore only one other collider? 0 Answers
changing gravity OnTriggerEnter 1 Answer
OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers