cutout_animation.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. it's 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 face 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 effecs, 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 attachment:gbot\_resources.zip .
  51. Setting up the Rig
  52. ~~~~~~~~~~~~~~~~~~
  53. Create an empty Node2D as root of the scene, weĺl 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 try 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*. Pick the object and
  77. move it normally. After the motion has begun and while the left mouse
  78. button is being held, press the "v" key *without releasing* the mouse
  79. button. Further motion will move the object around the pivot. This small
  80. tool allows adjusting the pivot easily. Finally, move the pivot to the
  81. right place:
  82. .. image:: /img/tutovec_torso2.gif
  83. Now it looks good! Let's continue adding body pieces, starting by the
  84. right arm. Make sure to put the sprites in hierarchy, so their rotations
  85. and translations are relative to the parent:
  86. .. image:: /img/tuto_cutout6.png
  87. This seems easy, so continue with the right arm. The rest should be
  88. simple! Or maybe not:
  89. .. image:: /img/tuto_cutout7.png
  90. Right. Remember your tutorials, Luke. In 2D, parent nodes appear below
  91. children nodes. Well, this sucks. It seems Godot does not support cutout
  92. rigs after all. Come back next year, maybe for 1.2.. no wait. Just
  93. Kidding! It works just fine.
  94. But how can this problem be solved? We want the whole to appear behind
  95. the hip and the torso. For this, we can move the nodes behind the hip:
  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,
  102. :ref:`RemoteTransform2D <class_RemoteTransform2D>`.
  103. This node will transform nodes that are sitting somewhere else in the
  104. hierarchy, by copying it's transform to the remote node.
  105. This enables to have a visibility order independent from the
  106. hierarchy.
  107. Simply create two more nodes as children from torso, remote\_arm\_l and
  108. remote\_hand\_l and link them to the actual sprites:
  109. .. image:: /img/tuto_cutout9.png
  110. Moving the remote transform nodes will move the sprites, allowing to
  111. easily animate and pose the character:
  112. .. image:: /img/tutovec_torso4.gif
  113. Completing the Skeleton
  114. ~~~~~~~~~~~~~~~~~~~~~~~
  115. Complete the skeleton by following the same steps for the rest of the
  116. parts. The resulting scene should look similar to this:
  117. .. image:: /img/tuto_cutout10.png
  118. The resulting rig should be easy to animate, by selecting the nodes and
  119. rotating them you can animate forward kinematic (FK) efficiently.
  120. For simple objects and rigs this is fine, however the following problems
  121. are common:
  122. - Selecting sprites can become difficult for complex rigs, and the
  123. scene tree ends being used due to the difficulty of clicking over the
  124. proper sprite.
  125. - Inverse Kinematics is often desired for extremities.
  126. To solve these problems, Godot supports a simple method of skeletons.
  127. Skeletons
  128. ~~~~~~~~~
  129. Godot *does not really* support actual skeletons. What exists is a
  130. helper to create "bones" between nodes. This is enough for most cases,
  131. but the way it works is not completely obvious.
  132. As an example, let's turn the right arm into a skeleton. To create
  133. skeletons, a chain of nodes must be selected from top to bottom:
  134. .. image:: /img/tuto_cutout11.png
  135. Then, the option to create a skeleton is located at Edit [STRIKEOUT:>
  136. Skeleton]> Make Bones:
  137. .. image:: /img/tuto_cutout12.png
  138. This will add bones covering the arm, but the result is not quite what
  139. is expected.
  140. .. image:: /img/tuto_cutout13.png
  141. It looks like the bones are shifted up in the hierarchy. The hand
  142. connects to the arm, and the arm to the body. So the question is:
  143. - Why does the hand lack a bone?
  144. - Why does the arm connect to the body?
  145. This might seem strange at first, but will make sense later on. In
  146. traditional skeleton systems, bones have a position, an orientation and
  147. a length. In Godot, bones are mostly helpers so they connect the current
  148. node with the parent. Because of this, **toggling a node as a bone will
  149. just connect it to the parent**.
  150. So, with this knowledge. Let's do the same again so we have an actual,
  151. useful skeleton.
  152. The first step is creating an endpoint node. Any kind of node will do,
  153. but
  154. :ref:`Position2D <class_Position2D>`
  155. is preferred because it's visible in the editor. The endpoint node will
  156. ensure that the last bone has orientation
  157. .. image:: /img/tuto_cutout14.png
  158. Now select the whole chain, from the endpoint to the arm and create
  159. bones:
  160. .. image:: /img/tuto_cutout15.png
  161. The result resembles a skeleton a lot more, and now the arm and forearm
  162. can be selected and animated.
  163. Finally, create endpoints in all meaningful extremities and connect the
  164. whole skeleton with bones up to the hip:
  165. .. image:: /img/tuto_cutout16.png
  166. Finally! the whole skeleton is rigged! On close look, it is noticeable
  167. that there is a second set of endpoints in the hands. This will make
  168. sense soon.
  169. Now that a whole skeleton is rigged, the next step is setting up the IK
  170. chains. IK chains allow for more natural control of extremities.
  171. IK Chains
  172. ~~~~~~~~~
  173. To add in animation, IK chains are a powerful tool. Imagine you want to
  174. pose a foot in a specific position in the ground. Moving the foot
  175. involves also moving the rest of the leg bones. Each motion of the foot
  176. involves rotating several other bones. This is quite complex and leads
  177. to imprecise results.
  178. So, what if we could just move the foot and let the rest of the leg
  179. accommodate to the new foot position?
  180. This type of posing is called IK (Inverse Kinematic).
  181. To create an IK chain, simply select a chain of bones from endpoint to
  182. the base for the chain. For example, to create an IK chain for the right
  183. leg select the following:
  184. .. image:: /img/tuto_cutout17.png
  185. Then enable this chain for IK. Go to Edit [STRIKEOUT:> Skeleton]> Make
  186. IK Chain
  187. .. image:: /img/tuto_cutout18.png
  188. As a result, the base of the chain will turn *Yellow*.
  189. .. image:: /img/tuto_cutout19.png
  190. Once the IK chain is set-up, simply grab any of the bones in the
  191. extremity, any child or grand-child of the base of the chain and try to
  192. grab it and move it. Result will be pleasant, satisfaction warranted!
  193. .. image:: /img/tutovec_torso5.gif
  194. Animation
  195. ~~~~~~~~~
  196. The following section will be a collection of tips for creating
  197. animation for your rigs. If unsure about how the animation system in
  198. Godot works, refresh it by checking again the :ref:`doc-animations`.
  199. 2D Animation
  200. ------------
  201. When doing animation in 2D, a helper will be present in the top menu.
  202. This helper only appears when the animation editor window is opened:
  203. .. image:: /img/tuto_cutout20.png
  204. The key button will insert location/rotation/scale keyframes to the
  205. selected objects or bones. This depends on the mask enabled. Green items
  206. will insert keys while red ones will not, so modify the key insertion
  207. mask to your preference.
  208. Rest Pose
  209. ~~~~~~~~~
  210. These kind of rigs do not have a "rest" pose, so it's recommended to
  211. create a reference rest pose in one of the animations.
  212. Simply do the following steps:
  213. 1. Make sure the rig is in "rest" (not doing any specific pose).
  214. 2. Create a new animation, rename it to "rest".
  215. 3. Select all nodes (box selection should work fine).
  216. 4. Select "loc" and "rot" on the top menu.
  217. 5. Push the key button. Keys will be inserted for everything, creating
  218. a default pose.
  219. .. image:: /img/tuto_cutout21.png
  220. Rotation
  221. ~~~~~~~~
  222. Animating these models means only modifying the rotation of the nodes.
  223. Location and scale are rarely used, with the only exception of moving
  224. the entire rig from the hip (which is the root node).
  225. As a result, when inserting keys, only the "rot" button needs to be
  226. pressed most of the time:
  227. .. image:: /img/tuto_cutout22.png
  228. This will avoid the creation of extra animation tracks for the position
  229. that will remain unused.
  230. Keyframing IK
  231. ~~~~~~~~~~~~~
  232. When editing IK chains, is is not neccesary to select the whole chain to
  233. add keyframes. Selecting the endpoint of the chain and inserting a
  234. keyframe will automatically insert keyframes until the chain base too.
  235. This makes the task of animating extremities much simpler.
  236. Moving Sprites Above and Behind Others.
  237. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  238. RemoteTransform2D works in most cases, but sometimes it is really
  239. necessary to have a node above and below others during an animation. To
  240. aid on this the "Behind Parent" property exists on any Node2D:
  241. .. image:: /img/tuto_cutout23.png
  242. Batch Setting Transition Curves
  243. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244. When creating really complex animations and inserting lots of keyframes,
  245. editing the individual keyframe curves for each can become an endless
  246. task. For this, the Animation Editor has a small menu where changing all
  247. the curves is easy. Just select every single keyframe and (generally)
  248. apply the "Out-In" transition curve to smooth the animation:
  249. .. image:: /img/tuto_cutout24.png