Collider not working when I am inside model
Basically I am working on Golf Water Globe 3D game.
In this my Golf Ball can't able to collide with Globe. I have set Golf Ball as Sphere collider and attached rigidbody as well. Globe has Mesh collider.
Golf ball is inside globe. So at present Golf Ball is not at all colliding with Globe. Globe is open from bottom side and I double check this thing.
Tee on which Golf ball is standing that has Mesh collider, Golf ball gets collided fine with Tee.
So I am very confused in this. Please give some suggestion in this.
[2]: /storage/temp/62166-screen-shot-2016-01-17-at-81938-pm.png
Answer by Fattie · Jan 17, 2016 at 04:36 PM
I would like to tell you first that
YOU NEVER USE MESH COLLIDERS IN GAMES.
Notice immediately above where it says
YOU NEVER USE MESH COLLIDERS IN GAMES.
Hopefully you now understand that
YOU NEVER USE MESH COLLIDERS IN GAMES.
It is endlessly confusing that Unity included "mesh colliders" in the system, it leads to endless confusion like this. You'll find 1000s of questions about mesh colliders where the answer is "don't use mesh colliders". There are some extremely unusual situations where you use mesh colliders, and you in certain situations use them for the "ground", but generally they're never used.
So just to begin with, regarding your tee,
remove the mesh collider.
Use one (or maybe two) ordinary colliders to represent the tee. That's how you make games - for example, a car would be probably two box colliders. A dog might be represented by 3 or 4 colliders (or just one if you're not too close); and so on.
Many people don't realise this extremely basic aspect of game engineering. It causes huge confusion.
In this case just use maybe a cylinder collider and a small box collider on top to represent the tee (or indeed - just use one trivial box collider (tall and thin) and that will very likely be fine).
So first do that.
once you've done that and absolutely have the tee working (properly, using perhaps one box collider), come back for the main part of your question:
Secondly, regarding your main question, the fundamental reason your ball is not colliding with the "glass" collider:
don't forget colliders (and indeed mesh) are one-way.
The "collison" is of course on the outside of a collider.
There's no collision "leaving" a collider, it's meaningless. (Just as shaders only paint one side of mesh.)
You can see this explained often, example
http://answers.unity3d.com/questions/376773/inside-box-collider-falling-through-but-works-if-i.html
Note that you could indeed use it as a TRIGGER, to learn when something goes outside the collider (so, http://docs.unity3d.com/ScriptReference/Collider.OnTriggerExit.html and so on)
In any event, you are in the very unusual situation where you want to be "inside" a collider. It's unfortunate that your first project where you're just getting going -- you have not yet reached the point of realising you don't use mesh colliders in games -- has this issue.
After you fix the tee as explained above,
You can easily google many solutions for "I am inside a collider" or "inside-out collider".
Since the thing you are inside is a sphere, fortunately one solution is extremely easy:
http://answers.unity3d.com/answers/469959/view.html
Alternately if you want to "TURN THE MESH INSIDE OUT",
here's the FULL SOLUTION
http://answers.unity3d.com/answers/369468/view.html
To repeat, SIMPLY GOOGLE "hit mesh from inside" and you'll find many such solutions.
Thanks sir for all this information. but I think for globe I need to use mesh collider only. I can't able to find any other option for this object.
I understand your Tee object concept and implement same in game.
I want my golf ball collide with globe surface. Can designer help me in this? so that whatever mesh collider is generated gives me reverse effect.
You've got 2 spheres, so it's very straightforward to detect the collision yourself. It happens when the distance of the centre of the ball from the centre of the globe is (globeradius-ballradius).
Hi Bonfire, I'm not sure if you noticed, indeed I gave the OP the full code for that:
Hi Siddhart,
I guess something was not clear,
here is the FULL SOLUTION if you do want to "turn the mesh inside out"
http://answers.unity3d.com/answers/369468/view.html
note the last few sentences of the answer, i edited it
In my opinion this answer is far too dogmatic. Yes, if there's an alternative to using mesh colliders (and yes, in this case there is) then one should usually use it. But there isn't always a better alternative.
Hi Bon, Can you give an example where you've used a mesh collider?? include pic if you like. Or just describe the situation
I can't be specific (not allowed) but I've worked on several highly ranked mobile games that use them extensively. If precision is a priority and you have highly irregularly shaped objects then there might be no alternative.
$$anonymous$$esh colliders are fine for static objects where a primitive shape doesn't do a good enough job to detect when two things should be colliding... Please don't write your answers so absolute (and stop using unnecessarily large text). If you're annoyed; take a walk.
Also, knowing when something has left a volume is not "meaningless" and, similarly, knowing when something has stopped colliding is equally not "meaningless". That's why OnCollisionExit and the triggers you mentioned exist.
Damn, you must have only made very simple games in your life to be able to think this way. Next time try to use fonts and capslock like you are older than 10.
Answer by stvz · May 26, 2017 at 06:10 PM
@siddharth3322, simple, reverse normals of your mesh.,simple, reverse normals of your mesh.
Your answer
Follow this Question
Related Questions
Unity Annoyance with Physics Help C# Scripting Problem Momentum Issue Please Help 0 Answers
Collision Detection Modes not working for what I need? 0 Answers
Why is my Character's BoxCollider getting stuck in between two wall BoxColliders? 0 Answers
Why do I fall really far when I collide with something? 0 Answers