Impact Crater Effect

Impact Crater Effect

Project Overview

Using the concepts covered by Catlike Coding’s mesh deformation script as a base for this effect, I have added a few lines of code that delay the spring effect on the vertices after they are pushed.

The original code applies a force to the vertices of the mesh, forcing them to return to their original position as soon as the force pushing the mesh stops acting on it. This is what creates the “spring” effect on the mesh. By delaying when the force is applied to the vertexes, the deformation of the mesh is maintained for a set amount of time.

In order to have an object deform the mesh, I have added the deformation script use to detect the mouse input to the object. However, the magnitude of the force applied had to be multiplied considerably so the impact of the object could become more noticeable.

Effect results

Impact Crater Effect

At this point, what is shown above is the result obtained. While the effect is clearly visible on the sphere and the capsule used to demonstrate this effect, the deformation on the ground is not immediately evident. To add more impact to the deformation, I wanted to add a radial crack texture at the point of impact.

Since each impact will leave a crack on the surface hit, it would not be simple to modify the surface’s original texture. Doing so could lead to cracks appearing out of nowhere in any other objects that use the same texture. There would also be some awkward cases such as when the deformation is on the edge of the object.

The solution was to use a decal projector to add the crack textures to the impacted surfaces. The code goes as follows: get the normal of the first point hit by the deformer object, add the normal vector of the point to that position and then create the decal projector at the resulting point. This ensures that the projector will always be above the surface.

The code used to create the decal projectors also destroys them at the same time the mesh will begin to return to its original shape. However, the crack on the floor disappears too suddenly. To solve that, a script that fades the decal was added to the projector. The result was the following:

Impact Crater Effect

Finally, I used particle effects to add smoke and debris to the impact. The debris are particles with meshes that have gravity applied to them. They also have a trail particle attached to the sub-emitter of the particle system. This is the final result:

Impact Crater Effect