Physics-Driven Character Animation
Total Page:16
File Type:pdf, Size:1020Kb
Escuela Técnica Superior de Ingeniería Informática Physics-Driven Character Animation Memoria del Trabajo Fin de Grado Grado en Diseño y Desarrollo de Videojuegos Autor: Aitor Iribar Etxezarreta Tutores: Miguel A. Otaduy Mickeal Verschoor Septiembre 2020 Acknowledgements Gracias a Miguel A. Otaduy y a Mickeal Verschoor por ofrecerme vuestra ex- periencia cuando alcanzaba el límite de mis conocimientos matemáticos. Por obligarme a definir las fuerzas como muelles, y por tener paciencia durante me- ses de escribir esta memoria. Eskerrik asko, bihotzetik, ama eta aitari; azken urte hauek nire burua hobetzen pasatzeko aukeragatik, eta pozten nauen bidean zuen babesa emateagatik. Gracias, Elena, por todo tu apoyo emocional, y por cuánto me ayudaste a re- cuperarme. Gracias también a Codiguillos. Lo que empezó como un grupo para compartir apuntes se convirtió en algunas de mis amistades más preciadas. 1 Abstract Animation in videogames is traditionally implemented through key- frames. Keyframed animations are completely predefined, and lack the ability to react to forces and collisions. Ragdolls are often used when characters need to react to physics, but they can not be animated through keyframes, relegating the use of ragdolls to dead or unconscious characters only. This thesis proposes a method for animating ragdolls by calculating the necessary forces to match a keyframed animation. There exists tech- nology that achieves this, but most of it is proprietary, and little informa- tion on the subject is freely available. As well as proposing the Animation Matching method, the thesis details the development of Hairibar.Ragdoll, an implementation of the method for the Unity engine. This implement- ation is Free Open-Source Software, serving both as a tool and as an example. The Animation Matching method is designed to be intuitive and easy to use by non-technical animators. To this end, the thesis proposes a set of simple parameters to control the ragdoll’s behaviour. It is also designed in such a way that it acts as a post-processing layer that is compatible with any animation technology. The thesis evaluates the results via multiple benchmarks that simulate different use cases for the technology. Finally, it proposes several ways in which the method may be further extended. 2 Contents 1 Introduction 6 1.1 Context . 6 1.1.1 Keyframes . 6 1.1.2 Ragdolls . 7 1.2 Challenges . 7 1.3 Goals . 8 1.3.1 Functional goals . 8 1.3.2 Quality goals . 9 1.4 The thesis’s structure . 9 2 Related Work 11 2.1 Dynamic Motion Synthesis . 11 2.2 Authored Animation-based approach . 11 2.3 Active Ragdoll approach . 12 3 Animation Matching 14 3.1 Ragdoll simulation . 14 3.2 Pose definition . 15 3.2.1 Position . 15 3.2.2 Rotation . 16 3.3 Animation Matching forces . 17 3.3.1 Position Matching . 17 3.3.2 Rotation Matching . 18 3.4 Parameters . 19 3.4.1 Stiffness parameter . 19 3.4.2 Damping parameter . 21 3.4.3 Conclusion . 22 3.5 Power Profiles . 22 3.6 Collisions . 23 4 Implementation 24 4.1 Used technology . 24 4.1.1 Unity . 24 4.1.2 PhysX . 25 4.1.3 Ragdoll setup . 26 4.2 Event timeline . 29 3 4.2.1 The update loop . 29 4.2.2 The physics loop . 30 4.3 Architecture . 34 4.4 Core module . 34 4.4.1 Ragdoll profiles . 34 4.4.2 Ragdoll definitions . 36 4.4.3 Ragdoll settings . 42 4.4.4 Collision Ignorance . 46 4.4.5 Debug Tools . 47 4.5 Animation module . 48 4.5.1 Ragdoll animator . 49 4.5.2 Animation profiles . 50 4.5.3 Mecanim integration . 52 4.5.4 Collision reaction . 52 4.5.5 Power on transitioner . 53 4.5.6 Animated ragdoll wizard . 53 4.6 Extensibility . 54 4.6.1 IBoneProfileModifier . 54 4.6.2 ITargetPoseModifier . 55 4.6.3 Custom ragdoll profiles . 55 5 Tools & Methodology 56 5.1 Tools . 56 5.1.1 Microsoft Visual Studio . 56 5.1.2 Git . 56 5.1.3 HacknPlan . 56 5.2 Methodology . 57 5.2.1 Introduction to Kanban and HacknPlan . 57 5.2.2 Introduction to Git-flow . 57 5.2.3 Development workflow . 58 5.2.4 Data . 59 6 Results & Benchmarks 60 6.1 Benchmarks . 60 6.1.1 Basic Locomotion . 60 6.1.2 Colliding with Walls . 65 6.1.3 Walking Under an Obstacle . 66 6.1.4 Shooting Balls . 66 4 6.1.5 Hanging . 67 6.1.6 Climbing . 68 6.1.7 High Acceleration . 69 6.1.8 Local Space Waving . 69 6.2 Failed experiments . 70 6.2.1 Velocity Gain parameter . 71 6.2.2 Position Matching through Spring Joints . 71 6.2.3 Collision Give . 71 6.2.4 Maximum acceleration . 72 7 Conclusions 73 7.1 Realised goals . 73 7.1.1 Functional goals . 73 7.1.2 Quality goals . 73 7.2 Future work . 74 7.2.1 2D Support . 74 7.2.2 Better animation limiting . 74 7.2.3 Bone scaling and stretching support . 74 7.2.4 Dynamic adjustment of joint limits . 75 7.2.5 Support for omitting intermediate bones . 75 7.3 Closing . 76 References 77 5 1 Introduction Z = 1 Z = 0.3 1.1 Context To understand the method proposed in this thesis, and why it may prove be- neficial, it is important to understand the individual elements that it combines. This section will explain, at a high level, what keyframed animations and rag- dolls are. 1.1.1 Keyframes Traditional animation in videogames works via keyframes. A keyframe defines a position and rotation for every part of the character that can move (referred to as bones). See figure (1) for an example of the keyframes an animation may have. Figure 1: The different keyframes that may be defined for a typical jump anim- ation. Image from The Animator’s Survival Kit. To play a keyframed animation, each bone is positioned and rotated as described in the animation. They do not snap from keyframe to keyframe, though. For a given moment between keyframes, the positions and rotations defined in both keyframes are interpolated between, resulting in a new pose that is in between the two keyframes. This interpolation is visualised in figure (2). Keyframed animations are fixed - they can not react to the environment. The bones are simply moved to wherever the animation says, with no regard to collisions or forces that may be acting on the character. 6 Figure 2: Animators can control the interpolation between keyframes by editing curves. The square icons represent keyframes, while the lines represent the values that will be used for any given moment. 1.1.2 Ragdolls Many games feature characters that die. When a character dies, a keyframed death animation is often too static. If the character dies on a staircase, one would expect it to slide down the stairs and lie diagonally. Keyframed anima- tions lack the ability to adapt to the environment in this way. To achieve better results, it is common to switch the character to a ragdoll upon death. Game engines offer the ability to move objects via a physics simulation. Moreover, these objects can be attached to each other via joints. Joints can limit the ways in which the two attached objects can move; limiting their relative position and rotation. A ragdoll simulates the character bones as physics objects with joints that prevent movements that the human body can not perform. Ragdolls allow characters to become a dead weight and be animated by a physics simulation upon death instead of playing a static death animation. Ragdolls re- spect gravity and collisions, achieving much more dynamic and adaptive results. An example can be seen in figure (3). 1.2 Challenges Keyframed animations could potentially be greatly improved by the dynamic properties of ragdoll simulation. However, keyframes and ragdolls are funda- mentally incompatible. As keyframed animations directly move the bones to a predefined position, they can not be affected by a ragdoll simulation. Any movement caused by the simulation is overwritten by the animation. Furthermore, physics engines are not designed to handle objects that instantly move. Instantaneous movements can introduce extremely high forces to the sim- ulation, making it unstable. They can also break joints, sometimes irreversibly. 7 Figure 3: A dead character being simulated as a ragdoll. Left: what the char- acter looks like in the game. Right: what the physics engine is simulating. Objects could even be moved to inside a wall, resulting in the physics engine attempting to solve an impossible problem. 1.3 Goals The aim of this thesis is to propose and develop a system that enhances key- framed animations with the physical properties of ragdolls. This includes sec- ondary motion, collisions and reactions to forces. Multiple development efforts have achieved this previously, as described in sec- tion (2.2). However, none of them are freely available. Most of them are pro- prietary technology, and information about them is sparse. The system developed in this thesis will be Free Open-Source Software, and will be developed as an extension to the Unity engine, offering a free, ready- made solution for millions of users. Additionally, the proposed method will be applicable to any engine capable of physics simulation. At a high level, the system will work by always simulating the character as a ragdoll, even while playing animations. To play animations, bones will not be instantly positioned. Instead, a series of forces will be applied to the ragdoll such that, if unimpeded, the ragdoll will appear to play the animation. If the animation results in an impossible pose, e.g.