- Home /
How do I avoid mesh collider overlapping? (see image)
Hello, I´ve searched for days to solve this problem, but I can't find the right solution. This is the situation: I have a dice prefab with a mesh collider attached. The mesh collider component has a different mesh applied with lower poly count and the option convex is checked.
The rigidbody component options are:
mass=1
drag∠ular drag=0
use gravity=true
is kinematic=false
interpolate=none collision
detection=discrete
This is the code where I apply force on rolling the dice:
// cycle through dice instances
foreach(GameObject dice in diceInstanceList){
// check if current dice is in dice stack, if not roll it
if(!stackHandler.Contains(dice)){
// reset position
dice.transform.position = diceSpawn.position;
// reset rotation
dice.transform.Rotate(rndRotation());
// setup physics
dice.rigidbody.isKinematic = false;
dice.rigidbody.useGravity = true;
dice.rigidbody.mass = GamePlaySettings.diceMass;
dice.rigidbody.drag = GamePlaySettings.diceDrag;
dice.rigidbody.angularDrag = GamePlaySettings.diceAngularDrag;
dice.rigidbody.velocity = Vector3.zero;
// show dice
dice.renderer.enabled = true;
// push dice towards the board
dice.rigidbody.AddForce(transform.forward * GamePlaySettings.DiceForce);
} // - is dice in stack?
} // - foreach dice
Everything works fine but there are some overlapping issues. I roll (rigidbody.AddForce) 6 dice at the same time and the dice are overlapping each other. Look at the picture:
How do I avoid these issues? What am I doing wrong?
Thanks for your help and time! Best, Arne
These mesh colliders are waaaaaaaaaaaaaaaay too complex imo.
Answer by robertbu · Apr 15, 2014 at 05:55 PM
The overlap seems severe. Let me suggest two things to try. Go to:
Edit > Project Settings > Physics
Reduce or set to 0.0, Min Penetration For Penalty.
Go to:
Edit > project Settings > Time
Reduce 'Fixed Timestep'. Try 0.01 to start.
Given how sever the overlap, I'm not convinced that either of these suggestions will address your problem, but it is worth a try.
Hello robertbu! wow! that was a quick answer :)
I have set the penetration value to 0.0 and my fixed timestep is by 0.02. that gives me more realistic results! thanks a lot!
Your answer
Follow this Question
Related Questions
In which cases Mesh Colliders they should not be used? 1 Answer
Physics sphere slows down when rolling on two wire rails like pinball machine wireform ramp 0 Answers
Can't set position of Rigidbody precisely 0 Answers
Compute mesh inertia tensor failed - NOT the usual problem 0 Answers
Move rigidbody to position and still have forces act on it 0 Answers