- Home /
Weird collision with objects passing through each other
Hello everybody, I am a newbie in this field and for the first time I am experiencing the following kind of problem. I just have a "simple" environment built by myself. Each object of this environment has a mesh collider. My player is a simple capsule for the moment and I make it move using the call rigidbody.MovePosition(). Unfortunately it happens something weird which you can see in the video right below.
https://www.youtube.com/watch?v=Ztk_4xFV7is
So the questions are: 1) how can I solve the fact that my player can pass through objects even if they have a mesh collider? 2) after my player has passed through those objects he keeps moving alone, like pushed by a non-existing "force" or anyway with a linear movement. What is it caused by? Thanks in advance!
$$anonymous$$ark non-moving object with mesh colliders as static. Perhaps increase their collision detection mode one notch. Consider using simplified $$anonymous$$eshes for mesh colliders to save processing.
We would probably need to see some code.
I'm not sure that $$anonymous$$ovePosition will actually stop you moving. I believe all it does is check for collision events and generates them through the OnCollision routines.
Don't quote me, I could be wrong.
Answer by softrare · Jan 20, 2015 at 06:18 PM
A MeshCollider is quite the processing-heavy component. It is not ideal for the environment you have built. In your environment most objects can just as well (and even better) function with a rectangular collider (which in Unity is a BoxCollider). Also the speed of your character is determining whether the collision is happening. Test it: decrease the moving speed of your character substantially and you will see he is much less likely to go through things.
But if your game-/scene-design can afford it, I definitely recommend to use BoxColliders on all objects and a capsule collider for your character. You will see the difference quite clear.
Did this help you in any way? If so please mark the question as answered or if not, please state what problems you are still having.
I am still changing all the environment. That's why I didn't mark the question as answered. $$anonymous$$y environment is unfortunately composed by tiny pieces. In order to find out if the problem is really the elevated number of mesh collider, I am first trying to merge many components together and then I'll try to see if the situation gets better with the mesh colliders. Decreasing the speed of the player unfortunately didn't work out. I'll get back to you soon!
I changed the colliders from mesh collider to box collider and everything works correctly. thanks a lot :)
Your answer
Follow this Question
Related Questions
Camera Collision Not Working 0 Answers
How to speed up? 3 Answers
Maintain velocity after impact with kinematic rigidbody 1 Answer
Fast object on collider not working 1 Answer
GameObject sometimes collides, but sometimes goes through each other. 0 Answers