collisions to a code modified mesh

I imported a mesh from a modeling tool, and gave it a colider. It collides correctly with other objects when I run my app.

I then changed the vertex x,y,z position of some points in that mesh via a script (runs once in awake). I move the vertex as it is done in the unity3d procedural mesh example “crumple mesh”.

The modified mesh no longer handles collison correctly. The collisions act as if I never moved any of the vertex. As if the collision and physics are engines are not aware I changed the shape.

Is there a way I can tell unity to update the collision data it is using (because my code changed the mesh shape) and use the new modified shape?

You need to reassign the modified mesh to the MeshCollider component.

Forgot to mention that I am using a mesh colider not a primitive.

Thank you, I will try that!

Hey, where can I get this “crumple mesh” example? This sounds like the first stop en route to Morph Target City!

In procedural example project: http://unity3d.com/support/resources/example-projects/procedural-examples

Unless I am mistaken, the best way to do what you want to do is with multiple bodies with sphere colliders connected by joints (ragdoll). Unless your object doesn’t have to deform constantly, like for example if it only deforms when it is hit by a rocket.

How do I reassign the modified mesh to the MeshCollider component using script ?

Hi,

Did you get any response.?..

Thanks

No…What I am doing now is to have several collision Meshes that are activated when necessary.

The reason to have this is to slide over a moving surface ( ex. Ocean Surf Waves)…

RayCastcollider could do the job but couldn’t find any good working script that behaves like a rigidbody.

not sure if you still on this. there seems to be some change with unity 3.0 Previously
GetComponent().sharedMesh = meshFilter.mesh;

would work but in unity3 u need to null the mesh before assigning a new one.

GetComponent().sharedMesh = null;
GetComponent().sharedMesh = meshFilter.mesh;