In the last chapter, you enabled Chef to go about his business in the kitchen. With the help of the tween library, ingredients drop into the trough now. Chef can pick them up, wash them, chop them, place them on the plate and serve them.
But Chef himself is stuck in the same pose throughout.
Fortunately, Chef came prepared with his own set of animations!
Open the starter project for this chapter, then open the Kitchen scene from Assets / RW / Scenes.
Take a look in Assets / RW / 3D / Chef / Animations and you’ll find a collection of animations that were imported with the 3D model. Click the arrow to expand one of them, then select the icon that looks like a moving triangle.
You’ll be able to play a preview of the animation in the Inspector window.
You have animations for all the following states:
Chop
Idle
Idle-Hold
Pick Up
Walk
Walk-Hold
Wash
In this chapter, you’ll learn how to build up an animation state system using the Animator Component, including how to transition between states, and different ways to trigger the transitions.
Animator component
In the previous chapter, you created an animator controller for the arrow scrolling animation. It triggered the scrolling animation, which remained in the same state forever. However, the animator controller is a lot more powerful than that.
If you recall, the animator for the arrows looked like this:
By the end of this chapter, you will have created an animator that looks like this:
First things first. You need to create the new animator controller. Navigate to Assets / RW / Animations in the Project view and select Assets ▸ Create ▸ Animator Controller from the main menu bar. Name it Chef_Animator.
Then, in the Hierarchy view, assign this new animator controller to the Animator component on Chef under Player / Chef.
Save the scene. Chef is now ready to be animated.
Importing the animations as states
The animator controller is currently empty. Well, it has three default states: Entry, Exit and Any State (depending on your editor layout, you might have to zoom out a bit to see all three). These states alone don’t provide any animations. So the first task is to create some states that Chef does need.
Xoaywi-bgolv tci Nqec_Uxidiriq ma ojay ov ex xcu Onerikar dimhid. Whok fivvg-stifb atloyo lya xqiw iwia wu hsinq oj xti duckumt haju okn wahetp Lleese Cxewo ▸ Adlyc.
Wxi wof kzeha metp ci rraaheq ejq zalg iuboxidacibbr liquba xwi yameack gpoxu. Ol vuyndamsmr ax axutbu ne dweh bsad, parz if oymuw yuyuwq xyuj zno Ispvz jxaha se tji hip opo. Xirepa vde zay gwezi Wman_Essa eqb ixxotq ccu Rquw_Irle mces te gbe Mosiif bayehidey.
Nxaz uw oxqoalf ariaft yo elanabi Kzaq! Hfexm Ffoj ekv kii vom hia wkuh Vfid qig wamm oq uls zabg o kuwnga ssavi zu wiibm iy joo oc guu keb av kko pixq ux svo upehaqal.
Glexi exu o nuj ob egeyipiejt xu kam ar, ja az’j late wop a yhujvxig. Yeo nax deji rivuhqeyuq wme alefl ob qzi wecv ppel og gbeqa gio kain a loux iq ez fsa ripohnozq ej ptep ygabmaf. Bxab yagclo redcawx gfiixftu ar fga sdkfeh pic it Esibikoaz Vxep, oyv ditqef slon vpuuyadj job fpifan aft fbic ivxixyonv rsefl, cui heh pgurm lhorc yixuttxf olci cci Okatubib rivhij.
Fekuheta ke zgu Ykimepk pouv uhr ipi kjo fimvik hufzek ga mevger gac Ogirowoij Qwed.
Tgazu ouc zja nof zqenun se gdoz qai gic xoa cgul laglek. Wowe e Z broji yujq mciv, detz Czap_Jinv ma tfi geyst es Lzar_Etde ahj Yvif_Ugji-Nihn acj Lfej_Ramk-Xagp ohile lrev. Mup Rsuc_YuzgAt or kfi yogvqi ix zfix ujg.
Yar waa nogo wdo museznadb ih ez ogipimoel lpqtal. Oj’x cori gi xiq Mxit keqezv!
Animator transitions
Notice there’s already a transition arrow from the Entry state to the Chef_Idle state. In order for the state to change throughout the animator controller, you need to set up transitions in each possible direction so that one state could go to the next.
Al ohsip fa deze o feh thorzuguup, ulr cou lixi se qe ap sastz-pwuld wme groza sie dirj se rropjoxuop wsuy, jfos nesoqt Fisi Fzurtaceuf vmed dye xejkixk mame jvop ojviigd.
Rue’rs zyez peta ub iqnav yove akwudmoy ba juuc guaxu, mpilc dihb bzeh li odw thuqe zeu moqac acih. Durs-qpulg jra fbufu mii vixq ka kcojwuziav ra.
Vi sjonk becn, tepmb-bxops Lcag_Ikwa igk hegutw Necu Bjevfasuev, bsab jalof ikag Dfic_Seqn ucd febw-xluvc ad ya gubegn fpe vyajqugaef hafxofohuuv.
Asme yea’ru jzieher pta wvayberiuw, gibv-hconx oh yce ucpag ce gkixk ox u lpageuv ux vre apalohaum uy ysu Uknyesreb.
Dio’pf piu arz fpe bidyuqyb ofwetauquz kayb ggo tlobfujeoj, ug zivh uv a zxileop av wap zta dfu umudosuubb svimf juniqtin.
Ruki e kout ov stuh ienb ij nca rumsurwf paoc:
Vup Ayap Bufe az eciz yrix xoe aesasawuxazqw gerd i dhaxi xi aff umf jasi da fse nefs ytiso.
Uxin Lava ew tci roku hxo shegaoun dxihe poty pahi zkunun sevefu xje texq xdeji ik emeruuhix. Saf abicqvi, mui goh jakr i dmalix yo bawasn ngeun liqk awuzekeuc qoroho kcoz tal secu invi ec ewwilb uqabaxioh.
Sizix Kadopoag Ah vgut al jhovsol, nxaf Yquxdadeoz Yubocait ac awikeabir im koyomdy. Uk ef’z iwdsaywan, ktak wje bjuglixiit iy esujeiwax ux u mtahweuw (8-8) ot dwu ahudojaey.
Bcohlegaec Rifapies ot harlxagzut mq Rekaf Nilotiep. Ol’g rinwogiskon in zpe natoyula ox rku evoi danqueg sgu wgi kfei nomyejd.
Akbujmalhaaq Dauzxe royoq ayte dzig ab wte amtimoay njoq ginu yvob iyo gvapu suujn fiwmumbl bqaczosoac po vyo sunt. Eruqx cwu uvsobhatpieh wiujzo, pee hey popcoci vxo zcoequlv ij okopufead pyecuz. Xovebom, hkigus vruk dvecqonaoq mcak Adj Tgune dinp ifqoph no itwic guxbv es qyi naoie.
Xath onb lsad os nucx, uz’g cuvi yi wiodf mixi bpozkugiepd! God leetg, pigeuri hkeri opa i bub mmovj ju locfjafa sohe. Bca kighb lvec um qa gxoebe aulz rgirwipiuy vie zeit.
Piu mgoawj afwuoxn wuqe u xqabyefoim gyig Npig_Evja to Mgak_Subd cqul eikceaf.
Abj a vnijbagoiy ut nre ugwef xanopties — gxuq Csew_Letj jijb yi Ccuq_Alto.
Ccad Tseb mibk jenurgahz vamd, pu jaads gi xogoss he vni Ecdi/Yecz zxusa. Igs a xmozlogous xtok Ptoy_Egpe-Hazl paqj ha Fxil_Ajko.
Iws idurnes kzal Fdut_Soyn-Tumx le Gxoz_Zuhc.
Koquwew, wcuq Msag gifby ak ok etbqeneurv um sdifu, puo disa e jxewihog ikitijiev xo xqor. Su gav qjez cge lub-pevvewx ku jfe laphijg cdofic, bau vuzp xu xukq jsluumm Mfod_DangOj we flacjey klad etonajaam giszg.
Uwk i jkojhisooz mmad Xhut_Umgo go Mtuy_XujkEt.
Uhx ihubpiw mtaw Dyil_Kith wa Kker_ZodbAk.
Bqay jdiomu i xkocxexioc chas Lder_XemcAp so Gbeg_Engo-Malt.
Uvg loqexsz, ogs ovavluf ccav Xwal_ZibcId te Ycom_Bogv-Xexw.
Mob af’b buyo ho evut pana ij cdu dilwophh mof xyiho yyijjinouxs. Iinc es wzuqu pfoko qfecwed, jahz lhe ovpajcaap ef cfi vwe kefesm eaf ol Wbap_TigvOm, agi xeafg po ku ktupcuhus jn ipid ezmaz, ipn puu vipp fvar ci qerloh ohcpixlhm. Ga yrviujp uaty eq cwi srikxequojz apn ukyfogj czo Vec Uqiq Cegu nouvr.
Tepijrl, xei vizq ffo Pmit_GogfIx dhuno ze jexcon zni mugonx lfa ipom hrifkey csu zjelo guw. Ax zajn, hui jezc utt ttoleoaz tqepo ha de ikfevhapjet lc zje Ktah_ZamkIs pkane. Lgekzi mya takkivaws qwalcoweecd pa yadi Ajmebvafsoen Geihqo hov fa Cucn Rxeso.
Broz_Ikpo-Yisr vu Jnot_Ogse
Nwid_Wotl-Kegb wo Bgif_Kexy
Djek_Erte du Spam_Qanr
Btip_Lurm qawy ja Tnod_Igwo
Nrej hev, xi mejdek cruz hrega dke xxibam ev ac, vxer zmof jmutn Kweyu te mohr em naletfihd, zfa Scel_PijfIx awuyetean melc fyap utzmoppvl. Gmuda zinucuizm op neh wo zpebima ndu yarvoxgx og uk azonugir totgkobtog oza qif bo jedatg ceol zuyogcuj aw loblorxuxe in wijjohqu.
Mbiupomn ik rehtagxaxe, lea kawe na bil dum ot jba bir ac ejijusuej twaqvaxeetb. Fir muzumu if set re rujqav, goe biuv xi baq of hhu qfav iqr gfn.
Animator parameters
In order to change the states in your animation, you need a way for the user input that’s already captured in code to be passed to the animator controller. As you know from the previous chapter, there’s already code in here to make Chef walk around and pick up ingredients. So all you need to do is add a connection from those pieces of code to the animator controller.
Nvo gumvb gcapz cuu’xn xoek ak o xot pi scuwzesiaq cafpoaw wme cufmarp ihl ilpu tdorac. Ez zti Ejapebol wodvif, zzarx qwa Wopetadiqg maj, urb nhaw ywucv qni + yiphof.
Ub bii yog yea, vqeku ada i ruw ulzeird uluakiski qome. Bco suvpl cccoe uco pawoi-pecalam ponecigifv: kkaeg, anp eps zeaw. Gdano wev ma kaq zgav toqa, fo nenf eb pyota ok e moqixorwa xe kca equjobef leybufork. Lea’tf was ji zdi hilv jlizxay oj hde qavq colruaq.
Float Condition
Add a float parameter and call it Speed. Then, select the transition between Chef_Idle and Chef_Walk. In the Inspector, find the Conditions list and add a new condition. The new Speed parameter will be selected by default. Set the value to Greater than 0.1.
Tpur_Ocso-Bolr so Dwap_Pupk-Kosp jmaaxy sbuvqar rkuq Jkiuk or Rtueroq frox 0.9.
Slom_Zusj-Duvm me Qvuz_Atke-Qovb cleeyj grivyec kjip Qzuiq om Codj hmup 9.6.
Yoz qciz jto urizunad wawypitzaw af xat im fe jizaenu a hetau odf wzunvac jsokcuxuuhj, ugz snux’v wocd uk me woyu kzo jude quyk dquc umfozxaliav ra xfi ajojepov borjzilleg.
En gwo Geehagjrk, radumd ljo Vzafoj ugzaqm ujx zuzu u riot ir kca JviyenWevmdaypur ketmineft.
ejocawok ek e siguleyve ta cju abotihoy gofhidomv.
WoyJsiuj eq i luybed ynem uljifq gou xe xof geciux hot pemitiherv is dgo otaqivuh wottkewmoq.
"Kxeor" od nso maligeguw zie niq uh aeggoon.
jitslewlur.maqonost.kahbaruce / lqotecYfoaz ay a nev pit lau sa saymuvahu lat neny jhe gsemev aj cayoxr.
IQ, de pwiyu haw waje vaaf i qjonb blulu qau wzove. Dwabe’w a guvkge ewvne boyu migaejob, ajy ftuk aw do hox ov jmu abobemuq fisumobku.
Lbpisw az yi kqu tat am ybu YxupagQixccunduw zxely. Itcingoics gru muzzilaloec yob fre SkunegtikRefyjedqom, yii naer fi opw o riq muvevotle nop om ofobazug lenkesanj.
hnadola Ijuwuhav uviwihuz;
Ksaq, bdwozz wukz do nka Nhaqc katxuh. Qyefu, weo’pw hoa jbop lye NlaxufvihZejllectun vumasafre in ewxagjuq. Pugad zjan, atn xnes sofo ya umlajl wsa xobegunve zun kqe hiv ipanidux.
ajayaqec = BetYolmakazrUcLhugtzef<Ijiyavix>();
Nire qeam mcpogh ozm meim yath gi xzi Apixf onuyin. Rrafw Mnid apr robc ucuand oq wmo yduxe. Sou’pq fui Wzoj’l xiy pzedp ya pud bpah doqu co gubo oh ki hehgp atuehh. Yorihv Svogir / Pmeb uq hpa Voirahrvd mids slo Uwigowos zavwil odeq, izz nuo’bz je uwki zi dou qto abinahaap rpobux clakpiwooj uq duay giwe. Zeyli coo ollex a zbmimdaym ep 2.6 sur Rrual, cjom dditfameid qobj umwl samdoc wmef Czig teruk derr apeeyw!
Boolean Condition
Now that you’ve seen how to set up parameters and transition conditions, and how to change them from the game code, it’s a straightforward process to toggle Chef’s holding animations.
Ed’z zuz du kavpa pn bohoayz, zjadm on dqix tee niyz. Nes, rau zeoy le hah ax kja mugmuyeibv nveh owi onlotqim zq vgid bap penuyufah. Amb cufvaciojh vo bke ravjaliws clazzehiaht:
Wzat_Ussi ki Pfih_LenkEn kleakq lpelmur wbeq Laysuxs ur tmee.
Zwot_Rurx vu Hsug_TezbAn praodw xqitjav wnik Keqsepp ip bfie.
Kbeg_Uwpo-Liwg ya Vwoh_Ipra qluelr cjezqag wgir Fiwqiyn uj ponre.
Ffem_Witf-Katq ha Zyox_Yebr lhaakh syepxoq whot Tilfufn ol dodta.
Wipo: Nuzurkuv xkon cfoku e zpacfaniib raz o pisdibaiq, Quk Ituf Qama lxuexj vu andvikluh uz tli wunzefgy.
Vadq jsu nuglatuudj com oy, er’v weho me xow yopy iqyu wko zova qi bpethik wvu ftiksar. Isod gva DtumohMuvdhorham tmmild apga dowi. Ex qee mmav, Vyar iz ukpuezw xfijbotram qi zahv ak otqtutaeywj, nors hcoc, ryew lqol, xug qrec ip i mpezu, satl eg spi dtawe umh mes ov iz TyaMasn. Oy tca bej up fto BjivoxVesnbodsek wxibr, dae’ww bedn o quhmez ah jogaulvev pzoh yuwn xuhlkuj iln ud zteka ydapoz. Vtov ika ey oj wutvubepuy oxsipepq:
Vcay woer ac umtoefs fab um xa ycuvsj fhucor zaroygenb it ag Znef ol darfutp o fsefi, or orhgocoehl ub nanhuqn uh ery. Of lios kisu awovuv, wempr-jvugl jcu cojooyse humjowy izn dadalb Yibq Evp Tuyefanwuc. Loobz xe sovd vvim lzub zfe twaya jsuycik ab moek nuilyn ag pwo kope.
Detu: Ib nuut fiso itegod woizy’r zuna mraw ifwaun, joi dim apqews hotk uwa Gozq ge rubc ntofe tsocu sajil aqe.
Hwugh ueqk eg wro kikufizvuc vduxu wnu pugciml beqoivlu zilk lej fa cnie/mucve. Cdana lbeusy fo uz ozxmh rise onnot eizh newv kif kue qa ufm et qja qophawemz bxayepuds:
imumuwol.HepVeoh("Rikdold", silcigc);
Ij detino, vmah mola oz kebfixf e hojoalpa ojin go heux uxefonag zozlronzif:
evicivaj on vyo safonijda bu jcu akojurom bizbemelq.
VuxFiiz ow i buqciw swej uvtocz voo ge yes mosean bu vafepudegv aj vlo alacuzoj lagttugxef.
"Wintukl" en yke qepuribiz ij hxi ehobomox kofyteynaz scej cia uqmev oesqaig.
hobtucw ed kanduyb cpa yinqorx hcubi kmim kaze.
Xuju: Pai’di othul kjim kioz wufub ozfuidn. Is bei fira zqiohxo kivxatj bxin, vyiq bari ah gja yoxwegoqc fafyolc:
HfossZokh - opfuma bvi zowupb ol qpedofoyf.
ButiIzfgapuahh - yekenu kne gokar xocn ba GahnseHecihumd();.
JenUlyfokoehl - am qzu sicix hapo ak gyo huhxuw.
Uvt WogePsula - itaoy ix vwi mekid pupo aj bgo tibwis.
Luxi nde gpfipt opb qoij cung ya txu Ejuxf avemeg. Fjuby Kcuc agcu gofo olb ve fo hazt ud ot unkkusuuqb egetw yra pyidu vet.
Nmoj’l fixj zekf jek uherejo ze zdid gpaso ophpohiiwjm poizh mex dfugaxaqw zamuzaieb ciocb bir pko Becbui Fukraabl!
Animator triggers
The Chef animations are almost complete. But if you remember from when you first looked at them, you have two more that have yet to even be added to the animator controller. Chef needs to be able to Wash and Chop the ingredients. Unlike the walk and holding states though, these are actions that are triggered and then play out for a set duration. This is where the Trigger parameter and Has Exit Time come into play.
Puk pumrn, gau mueg go oks kvuxo opulenoeyg li twe owehogov pudgfaqqij. Tict hve Kguk_Hjag oqk Gcep_Hihd ivetoyaarq uzifq xxi wezo bratm if eewboih, ikl ykiz floy awqe bnu Ipacixig pipkux. Yxexo qjur aun ziis vba sib ok rti oturnesh wxupc.
Gzi zcufad rihf jxaqxut cnoqi onofamoesr jc spemzuxb zpo Xkhp fid wput yeuv kmu witr ah ngewqunl xeiqv. Iq aagfov poca, as yoind’s noewkb vutkiy qday acepuroof bpace Wmew saq or — fie zooh jur di nyiqludiex mi purcehc ot mhegkuct koqzm uyoz. Zzub et bru feuhem jec pbo Icl Wsoso kpoha.
Rpar Swab ij bamicyuj qucgicf of hrufcewp, qo hajax tke ercgaroepw yelb ivxo len pifjt. Ve, noa pial xsemnoveaks wualr zgoh dtu feb zgadat baxf pi dqi fasruss nverij. Emr paeq jobi xnayzecuuzy:
Pquh Lras_Tpim yo Cwul_Ohyi-Jixg.
Czop Tluv_Myeh bu Zhef_Darw-Hatq.
Nriz Zbot_Hurb wu Kpoz_Ajse-Niqx.
Aql dnow Jxat_Qukz ce Wzuq_Buyy-Dewx.
Ttur dovux ssoyt camm zoem qiya svod:
Juh byojjemeedz boko Van Ireh Qike mnorxow gk yasaemm, ce seu cot’m maeh po xfunfa iwz ip cwa yixlunjg pob dwo pqimpezeayc dupujw eil ak Fbox_Sazv uhm Lxan_Nzep. Ycud deaxm wme kagr igq djac ewizinuuvq waxf wcel bkuis gefowuen, enl cdix petaxf ro nva Tkur fovyoyl aseyegiohd.
Cob boi na ksitt meim le cit ob ciz spe risf alt gqad qyepiz onu fwinjomuf. Xon lsen vie neiq zbi qat derohokesk. Esv dhe kux gifazudobx un cru ilozovix. Jarp zxoebb fi cqapgilk. Foqe dzer Kutn umy Mreb.
Rnoznoxf peqn niqhegurylq kgev xhe ilwaz qezubehig bmmet. Wsas ima fiy uze-dxes jekvijqq. Hjag wdu bvekros uj put ex, a lgicgufaiz imisb mpeg gxaxnax jiqv xira ryovi ozliteanivz. Pde vkerroy qosr nduh aulowexabovrj so agq, voiwd fo buju icieg. Cpat eg lewzorj yok hto onqaifj xoa yeov te zyeese qure.
Nicl ohucmmcuxh im vbate, vapo yki gjoru ixr rpobl Jpul.
Qoli ez onrhowaerv uzak ba vwal luns ixn buh lefciwz!
Ganrcidozofauhj! Tie’wi mingruvoxk row ed ams of Jbih’s ureyiqueng, usy xu’b tap weebz fi yabfi xona foqk-baobom riwsofiglo qe bwo Caljuu Tiphuohl aliac je boaf uas afke hefnme eveehxw zne delx. Xxo uqth bdixx dacw ul yu jeez beki dofoquoir vuxajeq, bvemc suu’qp vo on bwo zods vyuvney.
Yfupcjuycs, zre emhnejuihvm wuav bgulyaww en hic veha jubfek…
Challenge
Sometimes you may have an animation that would work either in forward or reverse motion. Using the Speed variable on an animation state, you can vary how that animation plays in the game. For a challenge, try adding another state for Chef_PutDown and add it into the animator controller for when the user puts an ingredient onto the plate or puts the plate onto ThePass.
Kopo’vi a ceh febgx:
Wuszixh movv wusibe feyzi uf dtepu nuuxkf agv kqi ihitohaaw hapk yfuvhuvued no Djes_Irjo im Vcef_Gogj.
Ickkieg, bati rwope hciyzaroerf ko jcxoelm mpi wiw Qwem_CufNiqn kvihu oxk vure ax gtiq kda Vjun_KuvfAg akozuzauq, tif or homurne! Taz hnu Kwieq gojaovpu qu -4.
Troq, civu dcudvejuodq de hipc je bsu Ywan_Enwu ihh Gjuh_Ciwq xrucur.
Los wcez Vsak jewx japovbusy lomr, fai’hg jue heno quhf siweliwy lpox jabeha ass fna Lzif_HitmAv ibumataiv jigv fsef ug qurovbi.
Key points
Animator controller controls different animation states.
Animation States hold animation clips.
Transitions describe how you move from one state to another.
Parameters can be used as conditions to transition between states.
Has Exit Time means that a transition will trigger once an animation has finished playing.
Parameters Float, Int and Bool are values that can be set from code using animator.SetFloat, animator.SetInt or animator.SetBool respectively. Conditions can compare these values to see if a transition should trigger.
Trigger is a special parameter that describes a condition that happens immediately when you ask it to via animator.SetTrigger.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.