cutout_animation.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. .. _doc_cutout_animation:
  2. Cutout animation
  3. ================
  4. What is it?
  5. ~~~~~~~~~~~
  6. Cut-out is a technique of animating in 2D where pieces of paper (or
  7. similar material) are cut in special shapes and laid one over the other.
  8. The papers are animated and photographed, frame by frame using a stop
  9. motion technique (more info
  10. `here <http://en.wikipedia.org/wiki/Cutout_animation>`__).
  11. With the advent of the digital age, this technique became possible using
  12. computers, which resulted in an increased amount of animation TV shows
  13. using digital Cut-out. Notable examples are `South
  14. Park <http://en.wikipedia.org/wiki/South_Park>`__ or `Jake and the Never
  15. Land
  16. Pirates <http://en.wikipedia.org/wiki/Jake_and_the_Never_Land_Pirates>`__
  17. .
  18. In video games, this technique also become very popular. Examples of
  19. this are `Paper
  20. Mario <http://en.wikipedia.org/wiki/Super_Paper_Mario>`__ or `Rayman
  21. Origins <http://en.wikipedia.org/wiki/Rayman_Origins>`__ .
  22. Cutout in Godot
  23. ~~~~~~~~~~~~~~~
  24. Godot provides a few tools for working with these kind of assets, but
  25. its overall design makes it ideal for the workflow. The reason is that,
  26. unlike other tools meant for this, Godot has the following advantages:
  27. - **The animation system is fully integrated with the engine**: This
  28. means, animations can control much more than just motion of objects,
  29. such as textures, sprite sizes, pivots, opacity, color modulation,
  30. etc. Everything can be animated and blended.
  31. - **Mix with Traditional**: AnimatedSprite allows traditional animation
  32. to be mixed, very useful for complex objects, such as shape of hands
  33. and foot, changing facial expression, etc.
  34. - **Custom Shaped Elements**: Can be created with
  35. :ref:`Polygon2D <class_Polygon2D>`
  36. allowing the mixing of UV animation, deformations, etc.
  37. - **Particle Systems**: Can also be mixed with the traditional
  38. animation hierarchy, useful for magic effects, jetpacks, etc.
  39. - **Custom Colliders**: Set colliders and influence areas in different
  40. parts of the skeletons, great for bosses, fighting games, etc.
  41. - **Animation Tree**: Allows complex combinations and blendings of
  42. several animations, the same way it works in 3D.
  43. And much more!
  44. Making of GBot!
  45. ~~~~~~~~~~~~~~~
  46. For this tutorial, we will use as demo content the pieces of the
  47. `GBot <https://www.youtube.com/watch?v=S13FrWuBMx4&list=UUckpus81gNin1aV8WSffRKw>`__
  48. character, created by Andreas Esau.
  49. .. image:: /img/tuto_cutout_walk.gif
  50. Get your assets: :download:`gbot_resources.zip </files/gbot_resources.zip>`.
  51. Setting up the rig
  52. ~~~~~~~~~~~~~~~~~~
  53. Create an empty Node2D as root of the scene, we will work under it:
  54. .. image:: /img/tuto_cutout1.png
  55. OK, the first node of the model that we will create will be the hip.
  56. Generally, both in 2D and 3D, the hip is the root of the skeleton. This
  57. makes it easier to animate:
  58. .. image:: /img/tuto_cutout2.png
  59. Next will be the torso. The torso needs to be a child of the hip, so
  60. create a child sprite and load the torso, later accommodate it properly:
  61. .. image:: /img/tuto_cutout3.png
  62. This looks good. Let's see if our hierarchy works as a skeleton by
  63. rotating the torso:
  64. .. image:: /img/tutovec_torso1.gif
  65. Ouch, that doesn't look good! The rotation pivot is wrong, this means
  66. it needs to be adjusted.
  67. This small little cross in the middle of the
  68. :ref:`Sprite <class_Sprite>` is
  69. the rotation pivot:
  70. .. image:: /img/tuto_cutout4.png
  71. Adjusting the pivot
  72. ~~~~~~~~~~~~~~~~~~~
  73. The pivot can be adjusted by changing the *offset* property in the
  74. Sprite:
  75. .. image:: /img/tuto_cutout5.png
  76. However, there is a way to do it more *visually*. While hovering over the
  77. desired pivot point, simply press the "v" key to move the pivot there for the
  78. selected Sprite. Alternately, there is a tool in the tool bar that has a
  79. similar function.
  80. .. image:: /img/tutovec_torso2.gif
  81. Now it looks good! Let's continue adding body pieces, starting by the
  82. right arm. Make sure to put the sprites in hierarchy, so their rotations
  83. and translations are relative to the parent:
  84. .. image:: /img/tuto_cutout6.png
  85. This seems easy, so continue with the left arm. The rest should be
  86. simple! Or maybe not:
  87. .. image:: /img/tuto_cutout7.png
  88. Right. Remember your tutorials, Luke. In 2D, parent nodes appear below
  89. children nodes. Well, this sucks. It seems Godot does not support cutout
  90. rigs after all. Come back next year, maybe for 3.0.. no wait. Just
  91. Kidding! It works just fine.
  92. But how can this problem be solved? We want the left arm to appear behind
  93. the hip and the torso. For this, we can move the nodes behind the hip
  94. (note that you can bypass this by setting the Node2D Z property, but then you
  95. won't learn about all this!):
  96. .. image:: /img/tuto_cutout8.png
  97. But then, we lose the hierarchy layout, which allows to control the
  98. skeleton like.. a skeleton. Is there any hope?.. Of Course!
  99. RemoteTransform2D node
  100. ~~~~~~~~~~~~~~~~~~~~~~
  101. Godot provides a special node, :ref:`RemoteTransform2D <class_RemoteTransform2D>`.
  102. This node will transform nodes that are sitting somewhere else in the
  103. hierarchy, by applying the transform to the remote nodes.
  104. This enables to have a visibility order independent from the
  105. hierarchy.
  106. Simply create two more nodes as children from torso, remote_arm_l and
  107. remote_hand_l and link them to the actual sprites:
  108. .. image:: /img/tuto_cutout9.png
  109. Moving the remote transform nodes will move the sprites, allowing you to
  110. easily animate and pose the character:
  111. .. image:: /img/tutovec_torso4.gif
  112. Completing the skeleton
  113. ~~~~~~~~~~~~~~~~~~~~~~~
  114. Complete the skeleton by following the same steps for the rest of the
  115. parts. The resulting scene should look similar to this:
  116. .. image:: /img/tuto_cutout10.png
  117. The resulting rig will be easy to animate. By selecting the nodes and
  118. rotating them you can animate forward kinematics (FK) efficiently.
  119. For simple objects and rigs this is fine, however the following problems
  120. are common:
  121. - Selecting sprites can become difficult for complex rigs, and the
  122. scene tree ends being used due to the difficulty of clicking over the
  123. proper sprite.
  124. - Inverse Kinematics is often desired for extremities.
  125. To solve these problems, Godot supports a simple method of skeletons.
  126. Skeletons
  127. ~~~~~~~~~
  128. Godot doesn't actually support *true* Skeketons, but it does feature a
  129. helper to create "bones" between nodes. This is enough for most cases,
  130. but the way it works is not completely obvious.
  131. As an example, let's turn the right arm into a skeleton. To create
  132. skeletons, a chain of nodes must be selected from top to bottom:
  133. .. image:: /img/tuto_cutout11.png
  134. Then, the option to create a skeleton is located at Edit > Make Bones:
  135. .. image:: /img/tuto_cutout12.png
  136. This will add bones covering the arm, but the result is not quite what
  137. is expected.
  138. .. image:: /img/tuto_cutout13.png
  139. It looks like the bones are shifted up in the hierarchy. The hand
  140. connects to the arm, and the arm to the body. So the question is:
  141. - Why does the hand lack a bone?
  142. - Why does the arm connect to the body?
  143. This might seem strange at first, but will make sense later on. In
  144. traditional skeleton systems, bones have a position, an orientation and
  145. a length. In Godot, bones are mostly helpers so they connect the current
  146. node with the parent. Because of this, **toggling a node as a bone will
  147. just connect it to the parent**.
  148. So, with this knowledge. Let's do the same again so we have an actual,
  149. useful skeleton.
  150. The first step is creating an endpoint node. Any kind of node will do,
  151. but :ref:`Position2D <class_Position2D>` is preferred because it's
  152. visible in the editor. The endpoint node will ensure that the last bone
  153. has orientation.
  154. .. image:: /img/tuto_cutout14.png
  155. Now select the whole chain, from the endpoint to the arm and create
  156. bones:
  157. .. image:: /img/tuto_cutout15.png
  158. The result resembles a skeleton a lot more, and now the arm and forearm
  159. can be selected and animated.
  160. Finally, create endpoints in all meaningful extremities and connect the
  161. whole skeleton with bones up to the hip:
  162. .. image:: /img/tuto_cutout16.png
  163. Finally! the whole skeleton is rigged! On close look, it is noticeable
  164. that there is a second set of endpoints in the hands. This will make
  165. sense soon.
  166. Now that a whole skeleton is rigged, the next step is setting up the IK
  167. chains. IK chains allow for more natural control of extremities.
  168. IK chains
  169. ~~~~~~~~~
  170. IK chains are a powerful animation tool. Imagine you want to pose a character's foot in a specific position on the ground. Without IK chains, each motion of the foot would require rotating and positioning several other bones. This would be quite complex and lead to imprecise results.
  171. What if we could move the foot and let the rest of the leg self-adjust?
  172. This type of posing is called IK (Inverse Kinematic).
  173. To create an IK chain, simply select a chain of bones from endpoint to
  174. the base for the chain. For example, to create an IK chain for the right
  175. leg, select the following:
  176. .. image:: /img/tuto_cutout17.png
  177. Then enable this chain for IK. Go to Edit > Make IK Chain.
  178. .. image:: /img/tuto_cutout18.png
  179. As a result, the base of the chain will turn *Yellow*.
  180. .. image:: /img/tuto_cutout19.png
  181. Once the IK chain is set-up, simply grab any of the bones in the
  182. extremity, any child or grand-child of the base of the chain and try to
  183. grab it and move it. Result will be pleasant, satisfaction warranted!
  184. .. image:: /img/tutovec_torso5.gif
  185. Animation
  186. ~~~~~~~~~
  187. The following section will be a collection of tips for creating
  188. animation for your rigs. If unsure about how the animation system in
  189. Godot works, refresh it by checking again the :ref:`doc_animations`.
  190. 2D animation
  191. ------------
  192. When doing animation in 2D, a helper will be present in the top menu.
  193. This helper only appears when the animation editor window is opened:
  194. .. image:: /img/tuto_cutout20.png
  195. The key button will insert location/rotation/scale keyframes to the
  196. selected objects or bones. This depends on the mask enabled. Green items
  197. will insert keys while red ones will not, so modify the key insertion
  198. mask to your preference.
  199. Rest pose
  200. ~~~~~~~~~
  201. These kind of rigs do not have a "rest" pose, so it's recommended to
  202. create a reference rest pose in one of the animations.
  203. Simply do the following steps:
  204. 1. Make sure the rig is in "rest" (not doing any specific pose).
  205. 2. Create a new animation, rename it to "rest".
  206. 3. Select all nodes (box selection should work fine).
  207. 4. Select "loc" and "rot" on the top menu.
  208. 5. Push the key button. Keys will be inserted for everything, creating
  209. a default pose.
  210. .. image:: /img/tuto_cutout21.png
  211. Rotation
  212. ~~~~~~~~
  213. Animating these models means only modifying the rotation of the nodes.
  214. Location and scale are rarely used, with the only exception of moving
  215. the entire rig from the hip (which is the root node).
  216. As a result, when inserting keys, only the "rot" button needs to be
  217. pressed most of the time:
  218. .. image:: /img/tuto_cutout22.png
  219. This will avoid the creation of extra animation tracks for the position
  220. that will remain unused.
  221. Keyframing IK
  222. ~~~~~~~~~~~~~
  223. When editing IK chains, is is not necessary to select the whole chain to
  224. add keyframes. Selecting the endpoint of the chain and inserting a
  225. keyframe will automatically insert keyframes until the chain base too.
  226. This makes the task of animating extremities much simpler.
  227. Moving sprites above and behind others.
  228. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229. RemoteTransform2D works in most cases, but sometimes it is really
  230. necessary to have a node above and below others during an animation. To
  231. aid on this the "Behind Parent" property exists on any Node2D:
  232. .. image:: /img/tuto_cutout23.png
  233. Batch setting transition curves
  234. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235. When creating really complex animations and inserting lots of keyframes,
  236. editing the individual keyframe curves for each can become an endless
  237. task. For this, the Animation Editor has a small menu where changing all
  238. the curves is easy. Just select every single keyframe and (generally)
  239. apply the "Out-In" transition curve to smooth the animation:
  240. .. image:: /img/tuto_cutout24.png