cutout_animation.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. :article_outdated: True
  2. .. _doc_cutout_animation:
  3. Cutout animation
  4. ================
  5. What is it?
  6. ~~~~~~~~~~~
  7. Traditionally, `cutout animation <https://en.wikipedia.org/wiki/Cutout_animation>`__
  8. is a type of `stop motion animation <https://en.wikipedia.org/wiki/Stop_motion>`__
  9. in which pieces of paper (or other thin material) are cut into special shapes
  10. and arranged in two-dimensional representations of characters and objects.
  11. Characters' bodies are usually made out of several pieces. The pieces are
  12. arranged and photographed once for each frame of the film. The animator moves
  13. and rotates the parts in small increments between each shot to create the
  14. illusion of movement when the images are played back quickly in sequence.
  15. Simulations of cutout animation can now be created using software as seen in
  16. `South Park <https://en.wikipedia.org/wiki/South_Park>`__ and `Jake and the Never
  17. Land Pirates <https://en.wikipedia.org/wiki/Jake_and_the_Never_Land_Pirates>`__.
  18. In video games, this technique has also become popular. Examples of
  19. this are `Paper Mario <https://en.wikipedia.org/wiki/Super_Paper_Mario>`__ or
  20. `Rayman Origins <https://en.wikipedia.org/wiki/Rayman_Origins>`__ .
  21. Cutout animation in Godot
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Godot provides tools for working with cutout rigs, and is ideal for the workflow:
  24. - **The animation system is fully integrated with the engine**: This
  25. means animations can control much more than just motion of objects. Textures,
  26. sprite sizes, pivots, opacity, color modulation, and more, can all be animated
  27. and blended.
  28. - **Combine animation styles**: AnimatedSprite2D allows traditional cel animation
  29. to be used alongside cutout animation. In cel animation different animation
  30. frames use entirely different drawings rather than the same pieces positioned
  31. differently. In an otherwise cutout-based animation, cel animation can be used
  32. selectively for complex parts such as hands, feet, changing facial expressions,
  33. etc.
  34. - **Custom Shaped Elements**: Custom shapes can be created with
  35. :ref:`Polygon2D <class_Polygon2D>`
  36. allowing UV animation, deformations, etc.
  37. - **Particle Systems**: A cutout animation rig can be combined with particle
  38. systems. This can be useful for magic effects, jetpacks, etc.
  39. - **Custom Colliders**: Set colliders and influence areas in different
  40. parts of the skeletons, great for bosses and fighting games.
  41. - **Animation Tree**: Allows complex combinations and blending between
  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:
  51. `cutout_animation_assets.zip <https://github.com/godotengine/godot-docs-project-starters/releases/download/latest-4.x/cutout_animation_assets.zip>`_.
  52. Setting up the rig
  53. ~~~~~~~~~~~~~~~~~~
  54. Create an empty Node2D as root of the scene, we will work under it:
  55. .. image:: img/tuto_cutout1.png
  56. The first node of the model is the hip.
  57. Generally, both in 2D and 3D, the hip is the root of the skeleton. This
  58. makes it easier to animate:
  59. .. image:: img/tuto_cutout2.png
  60. Next will be the torso. The torso needs to be a child of the hip, so
  61. create a child sprite and load the torso texture, later accommodate it properly:
  62. .. image:: img/tuto_cutout3.png
  63. This looks good. Let's see if our hierarchy works as a skeleton by
  64. rotating the torso. We can do this be pressing :kbd:`E` to enter rotate mode,
  65. and dragging with the left mouse button. To exit rotate mode hit :kbd:`ESC`.
  66. .. image:: img/tutovec_torso1.gif
  67. The rotation pivot is wrong and needs to be adjusted.
  68. This small cross in the middle of the :ref:`Sprite2D <class_Sprite2D>` 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. Sprite2D:
  75. .. image:: img/tuto_cutout5.png
  76. The pivot can also be adjusted *visually*. While hovering over the
  77. desired pivot point, press :kbd:`V` to move the pivot there for the
  78. selected Sprite2D. There is also a tool in the tool bar that has a
  79. similar function.
  80. .. image:: img/tutovec_torso2.gif
  81. Continue adding body pieces, starting with the
  82. right arm. Make sure to put each sprite in its correct place in the hierarchy,
  83. so its rotations and translations are relative to its parent:
  84. .. image:: img/tuto_cutout6.png
  85. With the left arm there's a problem. In 2D, child nodes appear in front of
  86. their parents:
  87. .. image:: img/tuto_cutout7.png
  88. We want the left arm to appear *behind*
  89. the hip and the torso. We could move the left arm nodes behind the hip (above
  90. the hip node in the scene hierarchy), but then the left arm is no longer in its
  91. proper place in the hierarchy. This means it wouldn't be affected by the movement
  92. of the torso. We'll fix this problem with ``RemoteTransform2D`` nodes.
  93. .. note:: You can also fix depth ordering problems by adjusting the Z property
  94. of any node inheriting from Node2D.
  95. RemoteTransform2D node
  96. ~~~~~~~~~~~~~~~~~~~~~~
  97. The :ref:`RemoteTransform2D <class_RemoteTransform2D>` node transforms nodes
  98. somewhere else in the hierarchy. This node applies its own transform (including
  99. any transformation it inherits from its parents) to the remote node it targets.
  100. This allows us to correct the visibility order of our elements, independently of
  101. the locations of those parts in the cutout hierarchy.
  102. Create a ``RemoteTransform2D`` node as a child of the torso. Call it ``remote_arm_l``.
  103. Create another RemoteTransform2D node inside the first and call it ``remote_hand_l``.
  104. Use the ``Remote Path`` property of the two new nodes to target the ``arm_l`` and
  105. ``hand_l`` sprites respectively:
  106. .. image:: img/tuto_cutout9.png
  107. Moving the ``RemoteTransform2D`` nodes now moves the sprites. So we can create
  108. animations by adjusting the ``RemoteTransform2D`` transforms:
  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, but there are limitations:
  118. - Selecting sprites in the main viewport can become difficult in complex rigs.
  119. The scene tree ends up being used to select parts instead, which can be slower.
  120. - Inverse Kinematics (IK) is useful for animating extremities like hands and
  121. feet, and can't be used with our rig in its current state.
  122. To solve these problems we'll use Godot's skeletons.
  123. Skeletons
  124. ~~~~~~~~~
  125. In Godot there is a helper to create "bones" between nodes. The bone-linked
  126. nodes are called skeletons.
  127. As an example, let's turn the right arm into a skeleton. To create
  128. a skeleton, a chain of nodes must be selected from top to bottom:
  129. .. image:: img/tuto_cutout11.png
  130. Then, click on the Skeleton menu and select ``Make Bones``.
  131. .. image:: img/tuto_cutout12.png
  132. This will add bones covering the arm, but the result may be surprising.
  133. .. image:: img/tuto_cutout13.png
  134. Why does the hand lack a bone? In Godot, a bone connects a
  135. node with its parent. And there's currently no child of the hand node.
  136. With this knowledge let's try again.
  137. The first step is creating an endpoint node. Any kind of node will do,
  138. but :ref:`Marker2D <class_Marker2D>` is preferred because it's
  139. visible in the editor. The endpoint node will ensure that the last bone
  140. has orientation.
  141. .. image:: img/tuto_cutout14.png
  142. Now select the whole chain, from the endpoint to the arm and create
  143. bones:
  144. .. image:: img/tuto_cutout15.png
  145. The result resembles a skeleton a lot more, and now the arm and forearm
  146. can be selected and animated.
  147. Create endpoints for all important extremities. Generate bones for all
  148. articulable parts of the cutout, with the hip as the ultimate connection
  149. between all of them.
  150. You may notice that an extra bone is created when connecting the hip and torso.
  151. Godot has connected the hip node to the scene root with a bone, and we don't
  152. want that. To fix this, select the root and hip node, open the Skeleton menu,
  153. click ``clear bones``.
  154. .. image:: img/tuto_cutout15_2.png
  155. Your final skeleton should look something like this:
  156. .. image:: img/tuto_cutout16.png
  157. You might have noticed a second set of endpoints in the hands. This will make
  158. sense soon.
  159. Now that the whole figure is rigged, the next step is setting up the IK
  160. chains. IK chains allow for more natural control of extremities.
  161. IK chains
  162. ~~~~~~~~~
  163. IK stands for inverse kinematics. It's a convenient technique for animating the
  164. position of hands, feet and other extremities of rigs like the one we've made.
  165. Imagine you want to pose a character's foot in a specific position on the ground.
  166. Without IK chains, each motion of the foot would require rotating and positioning
  167. several other bones (the shin and the thigh at least). This would be quite
  168. complex and lead to imprecise results. IK allows us to move the foot directly
  169. while the shin and thigh self-adjust.
  170. .. note::
  171. **IK chains in Godot currently work in the editor only**, not
  172. at runtime. They are intended to ease the process of setting keyframes, and are
  173. not currently useful for techniques like procedural animation.
  174. To create an IK chain, select a chain of bones from endpoint to
  175. the base for the chain. For example, to create an IK chain for the right
  176. leg, select the following:
  177. .. image:: img/tuto_cutout17.png
  178. Then enable this chain for IK. Go to Edit > Make IK Chain.
  179. .. image:: img/tuto_cutout18.png
  180. As a result, the base of the chain will turn *Yellow*.
  181. .. image:: img/tuto_cutout19.png
  182. Once the IK chain is set up, grab any child or grand-child of the base of the
  183. chain (e.g. a foot), and move it. You'll see the rest of the chain adjust as you
  184. adjust its position.
  185. .. image:: img/tutovec_torso5.gif
  186. Animation tips
  187. ~~~~~~~~~~~~~~
  188. The following section will be a collection of tips for creating animation for
  189. your cutout rigs. For more information on how the animation system in Godot
  190. works, see :ref:`doc_introduction_animation`.
  191. Setting keyframes and excluding properties
  192. ------------------------------------------
  193. Special contextual elements appear in the top toolbar when the animation editor
  194. window is open:
  195. .. image:: img/tuto_cutout20.png
  196. The key button inserts location, rotation, and scale keyframes for the
  197. selected objects or bones at the current playhead position.
  198. The "loc", "rot", and "scl" toggle buttons to the left of the key button modify
  199. its function, allowing you to specify which of the three properties keyframes
  200. will be created for.
  201. Here's an illustration of how this can be useful: Imagine you have a node which
  202. already has two keyframes animating its scale only. You want to add an
  203. overlapping rotation movement to the same node. The rotation movement should
  204. begin and end at different times from the scale change that's already set up.
  205. You can use the toggle buttons to have only rotation information added when you
  206. add a new keyframe. This way, you can avoid adding unwanted scale keyframes
  207. which would disrupt the existing scale animation.
  208. Creating a rest pose
  209. ~~~~~~~~~~~~~~~~~~~~
  210. Think of a rest pose as a default pose that your cutout rig should be set to
  211. when no other pose is active in your game. Create a rest pose as follows:
  212. 1. Make sure the rig parts are positioned in what looks like a "resting"
  213. arrangement.
  214. 2. Create a new animation, rename it "rest".
  215. 3. Select all nodes in your rig (box selection should work fine).
  216. 4. Make sure the "loc", "rot", and "scl" toggle buttons are all active in the
  217. toolbar.
  218. 5. Press the key button. Keys will be inserted for all selected parts storing
  219. their current arrangement. This pose can now be recalled when necessary in
  220. your game by playing the "rest" animation you've created.
  221. .. image:: img/tuto_cutout21.png
  222. Modifying rotation only
  223. ~~~~~~~~~~~~~~~~~~~~~~~
  224. When animating a cutout rig, often it's only the rotation of the nodes that
  225. needs to change.
  226. Location and scale are rarely used.
  227. So when inserting keys, you might find it convenient to have only the "rot"
  228. toggle active most of the time:
  229. .. image:: img/tuto_cutout22.png
  230. This will avoid the creation of unwanted animation tracks for position
  231. and scale.
  232. Keyframing IK chains
  233. ~~~~~~~~~~~~~~~~~~~~
  234. When editing IK chains, it's not necessary to select the whole chain to
  235. add keyframes. Selecting the endpoint of the chain and inserting a
  236. keyframe will automatically insert keyframes for all other parts of the chain too.
  237. Visually move a sprite behind its parent
  238. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  239. Sometimes it is necessary to have a node change its visual depth relative to
  240. its parent node during an animation. Think of a character facing the camera,
  241. who pulls something out from behind his back and holds it out in front of him.
  242. During this animation the whole arm and the object in his hand would need to
  243. change their visual depth relative to the body of the character.
  244. To help with this there's a keyframable "Behind Parent" property on all
  245. Node2D-inheriting nodes. When planning your rig, think about the movements it
  246. will need to perform and give some thought to how you'll use "Behind Parent"
  247. and/or RemoteTransform2D nodes. They provide overlapping functionality.
  248. .. image:: img/tuto_cutout23.png
  249. Setting easing curves for multiple keys
  250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. To apply the same easing curve to multiple keyframes at once:
  252. 1. Select the relevant keys.
  253. 2. Click on the pencil icon in the bottom right of the animation panel. This
  254. will open the transition editor.
  255. 3. In the transition editor, click on the desired curve to apply it.
  256. .. image:: img/tuto_cutout24.png
  257. 2D Skeletal deform
  258. ~~~~~~~~~~~~~~~~~~
  259. Skeletal deform can be used to augment a cutout rig, allowing single pieces to
  260. deform organically (e.g. antennae that wobble as an insect character walks).
  261. This process is described in a :ref:`separate tutorial <doc_2d_skeletons>`.