- Home /
Changing mesh collider's mesh cause objects go into mesh.
I am simulating jelly mesh with position based dynamics. I need to change mesh vertices and the collider need to change but sudden changes cause that some of objects go into mesh. I have simple code that follows second objects vertices as target vertices. I am not using dots or havok for now. But is there solution on dots side?@andrew-lukasik
targets = meshFilterMain.mesh.vertices;
Profiler.BeginSample("MyPieceOfCode");
for (int i = 0; i < vertices.Length; i++)
{
speeds[i] += changeSpeed *Time.fixedDeltaTime* (targets[i] - vertices[i]);
vertices[i] += speeds[i]*spring*Time.fixedDeltaTime;
speeds[i] *= damping*Time.fixedDeltaTime;
}
Answer by andrew-lukasik · Oct 03, 2021 at 09:26 PM
simulating jelly mesh (...)
Generally speaking, MeshCollider
is optimized to represent static (not moving) rigid body objects. Forcing it to be a soft body is outside it's specification. So what you're doing now is hacking something to do things it's is just not designed for; it can be done, but expect issues.
What you may want to do instead is to simulate your soft body as a lot of RigidBody
SphereCollider
s and move corresponding mesh vertices along with them (the same way bones move vertices in character animation). This will get rid of MeshCollider
, sudden intersections and open up you a path for multi-threaded dots physics as an option.
Note: Don't expect this to be easy.
Here is an example of this, made by a pro:
Thanks for answer . I have new question about dots. I used old code from u helped but dont work this time. Also I tried raise collide events and trigger events.
Your answer
![](https://koobas.hobune.stream/wayback/20220613043753im_/https://answers.unity.com/themes/thub/images/avi.jpg)