Squish Script

Programmer

Squish Script

Project Overview

While working on a Luchador themed Wrestling Game, there was a need for a script that would add stretch and squash effects to the game’s objects. Since I was not able to find a premade plugin that had the results I hoped for, I decided to create my own custom script.

The logic of the code

The code checks if the impact should trigger the squish animation whenever the object containing the script collides with another object. The script then gets the point of the impact, rotates the object slightly to face that point, then it changes the transform values of the object. The size is reduced on the axis of the impact and is increased on the other two axes, this makes the object look like it is being squished and stretched. After a certain amount of time passes, the object returns to its original size.

Obstacles met while coding the script

During testing, if an object was dropped into the ground, it could possibly trigger the script’s deformation animation multiple times, making it become a plane that would expand endlessly. The same could also happened whenever a player would jump on top of an object or if the object was thrown into a wall. Another issue that was found during tests happened whenever a player was carrying an object and something collided with that object. The fact that the object containing the script was parented to another object created multiple weird behaviors. Those include: the player being dragged by an unknown force, the object suddenly expanding to the point where it would push all other objects in the scene out of bounds, the object not returning to its original size, among multiple others.

Surprising side-effects

After tweaking the code and adding several checks in order to assure that most of the odd behaviors would not happen again, there was one very particular side-effect of adding the script to an object that was quite useful. If the player squished an object and stood on top of it when it reverted back to its original size, the object would propel the player upwards, effectively creating a small bounce effect. This was extremely well received by playtesters and I decided to keep it, after being sure that it would not interfere with any of the other major scripts created for the game.