cutout_animation.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 has also become 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, 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. We can do this be pressing ``E`` to enter rotate mode,
  64. and dragging with the left mouse button. To exit rotate mode hit ``ESC``.
  65. .. image:: img/tutovec_torso1.gif
  66. Ouch, that doesn't look good! The rotation pivot is wrong, this means
  67. it needs to be adjusted.
  68. This small little cross in the middle of the
  69. :ref:`Sprite <class_Sprite>` is
  70. the rotation pivot:
  71. .. image:: img/tuto_cutout4.png
  72. Adjusting the pivot
  73. ~~~~~~~~~~~~~~~~~~~
  74. The pivot can be adjusted by changing the *offset* property in the
  75. Sprite:
  76. .. image:: img/tuto_cutout5.png
  77. However, there is a way to do it more *visually*. While hovering over the
  78. desired pivot point, simply press the "v" key to move the pivot there for the
  79. selected Sprite. Alternately, there is a tool in the tool bar that has a
  80. similar function.
  81. .. image:: img/tutovec_torso2.gif
  82. Now it looks good! Let's continue adding body pieces, starting by the
  83. right arm. Make sure to put the sprites in hierarchy, so their rotations
  84. and translations are relative to the parent:
  85. .. image:: img/tuto_cutout6.png
  86. This seems easy, so continue with the left arm. The rest should be
  87. simple! Or maybe not:
  88. .. image:: img/tuto_cutout7.png
  89. Right. In 2D, parent nodes appear below children nodes. Well, this sucks.
  90. But how can this problem be solved? We want the left arm to appear behind
  91. the hip and the torso. For this, we can move the nodes behind the hip
  92. (note that you can bypass this by setting the Node2D Z property, but then you
  93. won't learn about all this!):
  94. .. image:: img/tuto_cutout8.png
  95. But then, we lose the hierarchy layout, which allows to control the
  96. skeleton like.. a skeleton. Is there any hope?.. Of Course!
  97. RemoteTransform2D node
  98. ~~~~~~~~~~~~~~~~~~~~~~
  99. Godot provides a special node, :ref:`RemoteTransform2D <class_RemoteTransform2D>`.
  100. This node will transform nodes that are sitting somewhere else in the
  101. hierarchy, by applying the transform to the remote nodes.
  102. This enables to have a visibility order independent from the
  103. hierarchy.
  104. Simply create two more nodes as children from torso, remote_arm_l and
  105. remote_hand_l and link them to the actual sprites:
  106. .. image:: img/tuto_cutout9.png
  107. Moving the remote transform nodes will move the sprites, allowing you to
  108. easily animate and pose the character:
  109. .. image:: img/tutovec_torso4.gif
  110. Completing the skeleton
  111. ~~~~~~~~~~~~~~~~~~~~~~~
  112. Complete the skeleton by following the same steps for the rest of the
  113. parts. The resulting scene should look similar to this:
  114. .. image:: img/tuto_cutout10.png
  115. The resulting rig will be easy to animate. By selecting the nodes and
  116. rotating them you can animate forward kinematics (FK) efficiently.
  117. For simple objects and rigs this is fine, however the following problems
  118. are common:
  119. - Selecting sprites can become difficult for complex rigs, and the
  120. scene tree ends being used due to the difficulty of clicking over the
  121. proper sprite.
  122. - Inverse Kinematics is often desired for extremities.
  123. To solve these problems, Godot supports a simple method of skeletons.
  124. Skeletons
  125. ~~~~~~~~~
  126. Godot doesn't actually support *true* Skeketons, but it does feature a
  127. helper to create "bones" between nodes. This is enough for most cases,
  128. but the way it works is not completely obvious.
  129. As an example, let's turn the right arm into a skeleton. To create
  130. skeletons, a chain of nodes must be selected from top to bottom:
  131. .. image:: img/tuto_cutout11.png
  132. Then, click on the Skeleton menu and select ``Make Bones``.
  133. .. image:: img/tuto_cutout12.png
  134. This will add bones covering the arm, but the result is not quite what
  135. is expected.
  136. .. image:: img/tuto_cutout13.png
  137. It looks like the bones are shifted up in the hierarchy. The hand
  138. connects to the arm, and the arm to the body. So the question is:
  139. - Why does the hand lack a bone?
  140. - Why does the arm connect to the body?
  141. This might seem strange at first, but will make sense later on. In
  142. traditional skeleton systems, bones have a position, an orientation and
  143. a length. In Godot, bones are mostly helpers so they connect the current
  144. node with the parent. Because of this, **toggling a node as a bone will
  145. just connect it to the parent**.
  146. So, with this knowledge. Let's do the same again so we have an actual,
  147. useful skeleton.
  148. The first step is creating an endpoint node. Any kind of node will do,
  149. but :ref:`Position2D <class_Position2D>` is preferred because it's
  150. visible in the editor. The endpoint node will ensure that the last bone
  151. has orientation.
  152. .. image:: img/tuto_cutout14.png
  153. Now select the whole chain, from the endpoint to the arm and create
  154. bones:
  155. .. image:: img/tuto_cutout15.png
  156. The result resembles a skeleton a lot more, and now the arm and forearm
  157. can be selected and animated.
  158. Finally, create endpoints in all meaningful extremities and connect the
  159. whole skeleton with bones up to the hip.
  160. You may notice when connecting the hip and torso, that an extra bone is created.
  161. To fix this, select the root and hip node, open the Skeleton menu, click ``clear bones``.
  162. .. image:: img/tuto_cutout15_2.png
  163. After fixing that your final skeleton should look something like this:
  164. .. image:: img/tuto_cutout16.png
  165. Finally! the whole skeleton is rigged! On close look, it is noticeable
  166. that there is a second set of endpoints in the hands. This will make
  167. sense soon.
  168. Now that a whole skeleton is rigged, the next step is setting up the IK
  169. chains. IK chains allow for more natural control of extremities.
  170. IK chains
  171. ~~~~~~~~~
  172. 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.
  173. What if we could move the foot and let the rest of the leg self-adjust?
  174. This type of posing is called IK (Inverse Kinematic).
  175. To create an IK chain, simply select a chain of bones from endpoint to
  176. the base for the chain. For example, to create an IK chain for the right
  177. leg, select the following:
  178. .. image:: img/tuto_cutout17.png
  179. Then enable this chain for IK. Go to Edit > Make IK Chain.
  180. .. image:: img/tuto_cutout18.png
  181. As a result, the base of the chain will turn *Yellow*.
  182. .. image:: img/tuto_cutout19.png
  183. Once the IK chain is set-up, simply grab any of the bones in the
  184. extremity, any child or grand-child of the base of the chain and try to
  185. grab it and move it. Result will be pleasant, satisfaction warranted!
  186. .. image:: img/tutovec_torso5.gif
  187. Animation
  188. ~~~~~~~~~
  189. The following section will be a collection of tips for creating
  190. animation for your rigs. If unsure about how the animation system in
  191. Godot works, refresh it by checking again the :ref:`doc_animations`.
  192. 2D animation
  193. ------------
  194. When doing animation in 2D, a helper will be present in the top menu.
  195. This helper only appears when the animation editor window is opened:
  196. .. image:: img/tuto_cutout20.png
  197. The key button will insert location/rotation/scale keyframes to the
  198. selected objects or bones. This depends on the mask enabled. Green items
  199. will insert keys while red ones will not, so modify the key insertion
  200. mask to your preference.
  201. Rest pose
  202. ~~~~~~~~~
  203. These kind of rigs do not have a "rest" pose, so it's recommended to
  204. create a reference rest pose in one of the animations.
  205. Simply do the following steps:
  206. 1. Make sure the rig is in "rest" (not doing any specific pose).
  207. 2. Create a new animation, rename it to "rest".
  208. 3. Select all nodes (box selection should work fine).
  209. 4. Select "loc" and "rot" on the top menu.
  210. 5. Push the key button. Keys will be inserted for everything, creating
  211. a default pose.
  212. .. image:: img/tuto_cutout21.png
  213. Rotation
  214. ~~~~~~~~
  215. Animating these models means only modifying the rotation of the nodes.
  216. Location and scale are rarely used, with the only exception of moving
  217. the entire rig from the hip (which is the root node).
  218. As a result, when inserting keys, only the "rot" button needs to be
  219. pressed most of the time:
  220. .. image:: img/tuto_cutout22.png
  221. This will avoid the creation of extra animation tracks for the position
  222. that will remain unused.
  223. Keyframing IK
  224. ~~~~~~~~~~~~~
  225. When editing IK chains, it is not necessary to select the whole chain to
  226. add keyframes. Selecting the endpoint of the chain and inserting a
  227. keyframe will automatically insert keyframes until the chain base too.
  228. This makes the task of animating extremities much simpler.
  229. Moving sprites above and behind others.
  230. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. RemoteTransform2D works in most cases, but sometimes it is
  232. necessary to have a node above and below others during an animation. To
  233. aid on this the "Behind Parent" property exists on any Node2D:
  234. .. image:: img/tuto_cutout23.png
  235. Batch setting transition curves
  236. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. When creating complex animations and inserting many keyframes,
  238. editing the individual keyframe curves for each can become an endless
  239. task. For this, the Animation Editor has a small menu where changing
  240. animation curves is easy. First select the appropriate keys. Next click on the
  241. pencil icon in the bottom right of the animation panel, this will open the
  242. transition editor. Now click on one of the curve options most appropriate for
  243. your animation.
  244. .. image:: img/tuto_cutout24.png