In this article I will talk about what I wrote to control the blend shapes in the game.
The first thing I did was making a blend shape class. I used this class to group the max and min of a blend shape and to store the value of the blend shape for later use. I also use it to find out which of the blend shapes is currently selected. It also has a method which can be used to switch between minimum and maximum values.
Here you can see how the transform body script works in the inspector. You can add all the different blend shapes here and tell the game what indexes they all have in the skinned mesh renderer. I also added a text component to show the current selected body part and how much you scale per button press (and also how much per lerp that is). I also added a maximum and middle size. Middle size is used to determine when there needs to be switched between maximum and minimum values. The maximum is used to know when the user is not allowed to press the buttons anymore. I also used this to exaggerate the blend shapes while testing, which worked great to help make them more visible.
Here you can see the code I wrote for the component above.The first interesting part is the StartScaling(). This is connected to the left and right buttons. If the game is not currently already scaling the ScaleBody() coroutine will be started.
In the ScaleBody() coroutine the button that is pressed will be used to determine how the selected body part should scale. This is also where isMin from the blend shape class is used. This is because the minimum values of the blend shapes are also with a maximum of 100 instead of -100. This makes it so that the values go from 100 – 0 – 100.
The last part of the code is where the selected body part is changed when the user presses up or down. This is done with a for-loop, where the current selected body part is found and then the next or the previous one is turned on. Then, the old one is turned off. Lastly, the text UI element that shows the selected body part is updated.
Reflection
What I learned from this is that you need a lot of logic, because I really had to use that for the last two screen-shotted parts. There were some things going wrong, which was because I used the for-loops incorrectly. I also learned that I need to do more research about how coroutines work, because my lerp does not work correctly and I also do not know when and why I need to use coroutines, I want to gain more knowledge about this.