Colliders for holes and diagonal shapes (Newbie),Which collider do I use?
So, we decided to make this little game where the players play pool, but instead of a white ball they have little cars that are shot at the balls directly. I've been trying for a few days now, I can't for the love of god figure out which collider to use for the pool table. We have a visual version of the pool table, and a simpler version I created in blender to try and get a working mesh collider for the stage. SPOILER: it's not working. Problem is that for some reason players are still able to glitch through the wall easily. I'm relatively new to unity. I thought about just using a compound collider, but creating them in unity for the whole table manually would take me ages and I can't figure out how to handle the different diagonal shapes and ground around the holes, which has these curves, since I can't rotate the colliders. Any of you have any tips? Am I missing something?!
Answer by streeetwalker · Apr 12, 2020 at 08:39 AM
Hi @BennyXUNITY , Interesting game Idea!
There could be a number of reasons for collisons "glitching out" One is relative velocity of the object with respect the the size of the collider. Objects that move to far in any given frame can overshoot the collider, missing it entirely. There are a number of ways to try to compensate for that.
Explain how do you want it to behave, in separate details:
You want your objects to realistically bounce of the table rails?
What about the pockets - do you want the cars to bounce out of a pocket if it hits too hard?
It looks like you are trying simulate what happens to balls once they go down into a pocket? Explain how you imagine that happening, and why you'd want to!
From there, what are you trying to do with diagonals?
I have to add, you don't want colliders for "hole" of the pockets - you want triggers, because you don't want the object to bounce off the "hole". Now if you want the concave area around the hole to behave as a true billiard table, that is a different story.
Answer by BennyXUNITY · Apr 12, 2020 at 04:21 PM
@streetwalker Hey, thanks for the quick answer. I actually would like the sides to behave like a normal pooltable with balls bouncing off, but I haven't really thought about how to do that yet, at the moment I'm focusing on just generally creating colliders for walls and bottom of the table that is more or less accurate to the model, so that I can test the shooting. I would like the balls to be able to bounce back from a pocket if hit too hard, but that's just for now, maybe down the line I'll think it's not as fun. My problem is some parts of the mesh collider on the sides are leaving holes for the cars and ball to be able to glitch through, which is giving me a bit of a headache. Generally manually placing box colliders in unity feels so unresponsive in the details. Like making sure the box collider for the ground is as accurate to the mesh as possible is kinda hard to do in unity.
For the holes, I already placed a big trigger collider under the stage that clip into the holes and outside of the arena. If a player or ball fall into a hole or get shout outside the stage they are placed back, no problems there.
How would you go about making colliders for the table? I can't make it from compounds, cause the balls would behave weird around the holes right?
@BennyXUNITY, If it were me I would not try to use a compound collider, and the only place you need a mesh collider is for the rails because those are not perfectly rectangular volumes. The rails are trapezoidal because they cut an angle next to the pockets - into the pockets. The bed can be a separate box collider.
If your not worried about the rail angle next to the pockets, you could just box colliders for the rails, but it isn't as nice. Or, you could use create a simple wedge collider shape and use them for the angled portion of each rail. You won't get a realistic simulation unless you handle that angle, somehow.
the thing would be to simplify the colliders as much as possible that the rails are pretty much symmetrical on a side. So using box colliders and wedge colliders placed to fit the rail shape makes it simpler.
Also, you want to handle the overshoot problem if your car's velocity is too high - one way to do that is extend the size of the colliders back from the inner face of the rail, and using box colliders make easier - make the collider much wider than the actual rail is, and offset it so that the edge of the collider aligns with the edge of the rail.
For the pockets, use cylindrical colliders set as triggers.
Put the all the colliders on empty game objects and align everything with your model. and parent them all together.
I think then you can let physics take over except for the pocket triggers where you actually have to check for OnTriggerEnter collisions.
Thank you so much. This seems like a pretty great implementation. I will try that later and get back to you if I have some other question. Thanks so much for the in depth explanation.
Your answer
Follow this Question
Related Questions
Adding collision to enemy model. Please help! 0 Answers
Imported Objects falling through imported terrain and non-imported terrain 1 Answer
Ball passes through the floor on movement 1 Answer
OverlapSphereNonAlloc Not Working? 1 Answer
Terrian Collider Or Mesh Collider Which Is Suitable For Mobile 0 Answers