Animating 2D Characters for Games in Blender™ Alan Thorn Cengage Learning PTR Animating2DCharactersforGamesin ©2015CengageLearningPTR. Blender™ CENGAGEandCENGAGELEARNINGareregisteredtrademarksofCengage AlanThorn Learning,Inc.,withintheUnitedStatesandcertainotherjurisdictions. PublisherandGeneralManager, ALLRIGHTSRESERVED.Nopartofthisworkcoveredbythecopyright CengageLearningPTR:StacyL.Hiquet hereinmaybereproduced,transmitted,stored,orusedinanyformorbyany AssociateDirectorofMarketing: meansgraphic,electronic,ormechanical,includingbutnotlimitedto SarahPanella photocopying,recording,scanning,digitizing,taping,Webdistribution, informationnetworks,orinformationstorageandretrievalsystems,except ManagerofEditorialServices: aspermittedunderSection107or108ofthe1976UnitedStatesCopyright HeatherTalbot Act,withoutthepriorwrittenpermissionofthepublisher. SeniorProductManager:EmiSmith ProjectEditor:KateShoup Forproductinformationandtechnologyassistance,contactusat TechnicalReviewer:MichaelDuggan CengageLearningCustomer&SalesSupport,1-800-354-9706. CopyEditor:KateShoup Forpermissiontousematerialfromthistextorproduct, submitallrequestsonlineatcengage.com/permissions. InteriorLayoutTech:MPSLimited Furtherpermissionsquestionscanbeemailedto CoverDesigner:MikeTanamachi [email protected]. Proofreader:KellyTalbotEditing Services BlenderisatrademarkofTheBlenderFoundation.Allothertrademarksare thepropertyoftheirrespectiveowners. Allimages©CengageLearningunlessotherwisenoted. ISBN-13:978-1-305-50184-3 ISBN-10:1-305-50184-5 eISBN-10: 1-305-50184-5 CengageLearningPTR 20ChannelCenterStreet Boston,MA02210 USA CengageLearningisaleadingproviderofcustomizedlearningsolutions withofficelocationsaroundtheglobe,includingSingapore,theUnited Kingdom,Australia,Mexico,Brazil,andJapan.Locateyourlocalofficeat: international.cengage.com/region. CengageLearningproductsarerepresentedinCanadabyNelson Education,Ltd. Foryourlifelonglearningsolutions,visitcengageptr.com. Visitourcorporatewebsiteatcengage.com. Acknowledgments ’ Writing a book is no simple matter. Although Im listed as the author, this book would not have been possible without the valuable help and fine work of many people, including ’ Emi Smith, Kate Shoup, Michael Duggan, and many others. Id like to say a big thank you to them, and also to you, the reader, for investing time to improve your skills. I hope this book proves helpful to you. Alan Thorn, 2014 London iii About the Author Alan Thorn is a game developer, freelance programmer, and author with more than 13 years of industry experience. He founded Wax Lyrical Games in 2010 and is the creator of the award-winning game Baron Wittard: Nemesis of Ragnarok. He is the author of 10 video training courses and 11 books on game development, including Unity 4 Funda- mentals, UDK Game Development, and Pro Unity Game Development with C#. He is also a ’ visiting lecturer for the game development masters degree at the National Film and Television School, London. Alan has worked on a freelance basis on more than 500 pro- jects, including games, simulators, kiosks, serious games, and augmented reality software for game studios, museums, and theme parks worldwide. He is currently working on an adventure game, Mega Bad Code, for desktop computers and mobile devices. iv Contents Introduction Chapter 1 Preparation and Modeling Step1:DrawingYourCharacter Step2:ImportingCharacterReferencesintoBlender Step3:ModelingfromReferences Step4:OptimizingTopologyforGamesandAnimation Step5:Housekeeping Conclusion Chapter 2 UV Mapping and Texturing Step6:RemovingDoubles Step7:CreatingtheCharacterAtlasTexture Step8:UVPreparationandProjection Step9:CreatingUVIslandsandMapping Step10:CompletingtheMapping Conclusion Chapter 3 Rigging, Bones, and Weights Step11:CreatingArmatures Step12:CreatingBones Step13:Skinning Step14:AdjustingtheWeighting v vi Contents Step15:ApplyingInverseKinematics Conclusion Chapter 4 Animation Step16:PreparingforAnimation Step17:BlockingIntheWalkCycle TheContactPose ThePassingPose TheDownPose TheUpPose Step18:MovingtheArms Conclusion Chapter 5 Exporting and Testing Step19:ExportingObjectsfromBlender Step20:ImportingObjectsintoUnity Step21:ConfiguringtheMesh Step22:TestingtheMesh Conclusion Introduction This eBook is aimed at readers looking to use Blender to create animated 2D characters ’ for video games. Itll be especially relevant to developers working with Unity, as I provide examples for importing characters into Unity. The main focus of this eBook, however, ’ is on Blenders tools and techniques for animating a 2D character through a complete looping walk cycle animation. It covers subjects such as modeling from reference, texture mapping and unwrapping, rigging, animation, and finally export-import workflows. Fur- ther, it outlines the basic mechanical stages of a walk cycle, which apply to most bipedal characters. ’ In describing this eBook, its important to stress several issues: n This eBook covers Blender, which is freely available software. It doesn’t cover ’ alternatives such as 3DS Max or Maya. This, however, doesnt mean the general ’ workflow and concepts covered here dont apply to those applications, because they do. It means only that all software-specific steps will be given in relation to Blender and its UI. n This eBook focuses on 2D characters as opposed to the more common 3D type. Consequently, this eBook is especially relevant for developers creating cartoon or stylized characters for their games. n In covering character animation, this eBook assumes you have a working familiarity with the Blender basics such as the UI, a control scheme, and a solid grasp of foundational concepts like box modeling, mesh editing, and object transforming. This eBook avoids unnecessary assumptions where possible, introducing concepts vii viii Introduction ’ and tools as though you were encountering them for the first time, but it doesnt ’ assume youre totally new to Blender. Tip If you’ve never used Blender before, or if you’re new to 3D modeling generally, I recommend checking out many of the books and tutorials on the Blender basics before getting started with this eBook. Good starting points includeTheCompleteGuidetoBlenderGraphicsby John M. Blain andBlenderFoundationsby Roland Hess. ’ With those points in mind, lets get started animating 2D characters with Blender! Chapter 1 Preparation and Modeling — Blender is renowned for creating 3D graphics and animation the kind found in real-time ’ 3D games and movie shorts like The Elephants Dream and Big Buck Bunny. For this rea- — — son, 2D character animation the kind found in cartoons may be regarded as an uncon- ventional use of Blender. Indeed, many avoid Blender altogether for this sort of animation. They often turn instead to Adobe Flash, Toon Boom Animate, Anime Studio Pro, or Synfig Studio. But this eBook will show you how to creatively adapt and reuse ’ Blenders 3D functionality to make professional-grade 2D character animation for games. Being able to do this is useful. It means Blender users can continue to use their free and cross-platform software and its familiar toolset to get their versatile work done. This can save time, effort, and money. This eBook is project-based. It focuses on the specific, real-world case of creating a fully animated character in Blender that can walk in a loopable cycle, as shown in Figure 1.1. ’ — Youll work through the complete animation process, from start to end from drawing board to a final game-ready model. The character to be created is named Pendragon, a carefree, clumsy homicide detective in ’ my upcoming game Mega Bad Code. One of Pendragons main design qualities is to pro- ’ vide comic relief for a dark and brooding storyline. In creating Pendragon, however, its important to be aware of the wider context and applicability of the knowledge contained ’ here. Certainly, in finishing this eBook and using the companion files, youll re-create the ’ — ’ animated Pendragon character. But youll have achieved much more than this youll have seen a complete animation toolset in Blender and gained first-hand experience of 1