Hi
I’ve found a few scripts for basic deforming, none of them suit my needs very well, and I’m not the best wuth unity and mesh alterations.
So lets say I have object I have object x in my hands. What I want is that every time I swing object x at object y, object y gets an exact spehere of mesh “removed” (Deformed, I know, but saying removed is easier) and I want the sphere centre to be the point where object x hit object y. So if you hit a flat plain with object x, you’d get an exact half sphere going inward.
Whats the best way of doing this?
(I’m quite new to mesh control, so treat me as a total begginner for this…)
Thanks
Jay
If you are new to mesh deformation then this is probably a rather ambitious project.
When a collider impacts with something else, its OnCollisionEnter function gets passed a list of contact points in the collision object. These points are described as a position and a normal vector, specifying the direction of force on the collider at that point. Given these pieces of information, it is possible to deform the mesh based on the contacts. The exact methods you use to determine where on the mesh the contact is and how to modify the mesh in response will depend on the type of effect you are looking for, the polygon density of the mesh and other factors. However, it is likely to be quite complicated unless you can find an existing solution that suits your needs.
Someone wrote a small system for mesh deformation on impact offering it as a unitypackage so you can use it in your project.
thread is on the showcase board but already a few months old without new posting I think
Old thread but you could take one of the code examples for mesh deformation and displace the vertices around the impact point. You’d work out the amount to inset each displaced vertex using the equation for calculating chord (also called ‘secant’) length - How to Calculate Chord Length | Sciencing.
Ie. imagine the plane intersecting with a sphere then for each vert on the plane within the sphere move the vert in the direction normal to the plane an amount equal to half the length of the chord of the sphere at that point (also in the normal direction).
Or you could use a gaussian function to determine displacement to get more of a classic ‘dimple’ shape.
You can use Impact Deformable, available on Unity Asset Store: Impact Deformable | Physics | Unity Asset Store