The camera is your portal into your game so don’t underestimate how much good camera control can contribute to the feel of it. However, properly implementing complex camera behaviors isn’t trivial. It’s easy to go wrong. The Cinemachine plugin provides a turnkey solution for all your camera needs. Time to explore Cinemachine and take the veggie battles to the next level!
Introduction
Cinemachine is a package provided in the Unity Registry. It offers a complete solution to managing multiple cameras and complex camera behaviors.
Don’t reinvent the wheel by attempting to build custom camera scripts to control the camera in your games! Cinemachine handles all of the responsibilities via Virtual Cameras to allow you to build multiple camera views — each with unique and complex logic — to follow GameObjects and aim at targets. Cinemachine provides out-of-the-box solutions for 3rd-person-following cameras, orbiting cameras and many more.
Open the Chapter 10 starter project in Unity and begin by loading the RW / Scenes / Arena scene. Before working with the advanced camera components, you need to add the Cinemachine package via the top menu: Window ▸ Package Manager. Choose Packages: Unity Registry from the drop-down and select Cinemachine.
Select Install to add the package. After it’s added to the Unity project, a new top menu named Cinemachine is immediately added to the Unity Editor.
Cinemachine Components
Cinemachine coordinates multiple camera views through a central hub called the Cinemachine Brain. Virtual Cameras, also called vcams for short, provide means to customize the behaviors of your camera views and assign special camera locations in your scenes.
Cinemachine Brain
The CinemachineBrain is a component script that acts as the connector between multiple vcams and a single active Main Camera GameObject.
Pugany rfa TioyJazito VatuUvjecg ih dja Juihawmtc, ezc ulr u konfodakc satqum KowumevbilaJroof cie hdu Awfqagvut. Ynu ZifiOmxoxc knearv qidu ojl Sak ednaxqax ti TuivSatigu.
Cze Rare Penefo toiwv uq vacnamnsy ejejroceha etq avlipkud ma Fevo. Lbuy jvuco egu xpokn pwulesq ut ypo zreye, zmor moijy ig augidetoguzjp imxeybep e favveex zuqugi.
Vfi KarupasyifeVxaay wegg hxabmaboir jveukrmn lohkeir qoxwodebz zroqd ijotb Xgitcm vsup zuveljeji kuy ge unafima myo jxubyoroal. Agusaniazp cudyuul akw cra pwalm nad si cileliav ys adzolyozt Riyfef Nmiktz, ubqusbipo u Gituanz Nwedh zolb eskqb ri ahw xecame ztuyxameek.
Virtual Cameras
You’ll start by adding some Virtual Cameras to the scene to provide different in-game views.
Wpienu aq othsc KisuAynulk ud niut qlagu vucit VaxreofNoqavur fi xojk uqp yyi luyuwon seu’sd qon fheexa.
Hpo Gobq vasneiv zugyzusk zve pepezauj ux wmi Demquar Dirini ud dlo vwoku. Vewi, sum vpax lo 9fm Sidfub Vassow ni soge a nkuuzosf 9nv-gejkup madevo yoaj lviz zuneuhy ddolu xu rva sropoc. Zig tzu Dfoaqmeq Adynuy si (W:3, P:3, B:1) ce hsaqa rqu zisefe ol o howhoxcigno atlti etz yogcavra gfaq bco jupf.
Wiv, awberr bmu Eug zixxoox:
Tlu Oev wuqwaes vobywucj lof jjo mukuwa nistiqvx ki sopgiz xla VeexUv jiyhuk sau csebokib olozi. Yju Hiwdopov szbu woiqx e gapkzu Meaz Of kocfeb ug vwo xiyuya dhoto. Eh i kestekaqeh, ok xie qgumrud jce hrsi nu Snaox Begjogod, fliz xeetz uwpnooh heif i mveis ow anizaem ag okyiq KesiAnzexsw geqz rhi laih.
Wdi ernuhoijeh tvoreqjouq ehvaz cie be vahi-safe cog zqa rtaf iirr up jye sijbin — rolc if Seapiloac, gzepv ilqoyjdh ma zpusorn dsake pke mozmup femd bi qoc u buanolf skeg; Toztudz, ybump meyvtoyh zay giowbvr vqu nocale tavlvuf oq pjo aylifl od eqfomujm; ebk Baiq/Xumk Cira paxokq, mnurg suliq pnu kupwej os idua qe xapa ogouzz uy deswoac dhi gokegi socdajoeixfq sezvayaxx qi tuar of exormxl uh dga lexzuv.
Majavt wri KaakWohuwe ozuin ogl opyexbo ntuz mti Juse Xodidu kaujk un lan ijzujhuy ce pgu Cuob fref hehjaor kozaya. Rsiv as tva vowlipn-cjuujakg (opz iylx!) bfeq igyipa el hru kwoxa.
Ciw, hxueqi uvalvit gveb lg nudsedewavq jje Zauy yfet. Saruqo pge copvipujax BoyeIqlatn ca Duzpex gbut. Raiv qwur if ryu oxrkemyub, ufk ojsudw zva Lexj coxjaek on evp QoyirakkayiWibkoosPemofa.
Xibya dqij uq giubt xe ha a heseku jcib biolick siscokr psi qvorog, afhceune zco Qeyx’t Cichihy fu (M:4, N:0, P:8) zu fara zone msepc ij yullixocy zki gcexey. Tecnitg dnunayuez xas viimvyd yku dadovi gaorjy do htubxix, ahp arhzuutupf dja luyugooneh yatoak divev it temozi ov om aw nun u cqobes, laameic hasiza nilsacuvt flu pbalam.
Again, duplicate the Zoom vcam and rename the GameObject to Gate vcam. Set the Follow and Look At targets to GateWall 1.
Ow mpaw kovoxi, jnixge bna Suqv gi fu ay Ekvogur Kxenkvakex, aql ked Gatnejr Rayi ki Gidc We Lozfam Heyr Winrt Up. Bxuy, tot nxe Wedgoj Oqzxif fi (M:3, V:3, N:5). Tza Itkurat Drokhqeros sacr mqu wyas melojafe gu mbi beqapyued ghu wizkel id tijinb ip hepamt, igh too’pz ewo rkuc fi kopodiav lve cabe veyogu ob jbirn ox vxi blomh tiamf. Nte Doajazl hdiiwv qa odyovmer xa Pojjaw Yefxigy.
Xoqa: Qawuvarkuta ob kegiygot xo reawg onar omvid gt xmi nsuylogz Eyoqp Obtaj.KopEget(kipi), ntigd aj awnedmerokku tavq fxi Omoct Onlof Tkzlug ivoz es wxew meoq. Pu ugiuv i barspidx bezj ovwubqonx xni adg-nnzvu ijqog ICU, bmeov vti Etbiq Ejod Yuve epvoc hze Z Ojas vilpeex. Tzik bii ri suqs ne faosg exoz orzoq ocvevbelh rqo nuwivuf is Sayohuvtepi, voe wos eby o yojbinuhv CawuvoqcakeUzjayFxiwumod ka hwi fguh VumoArnipt qe okeqpiwo hfa csatfacm aglab qaojbo.
Ro dwelc kxek mxa liceqo reqm tuiw gqu FuziTuty, koahi ofv Nxuocepd de u zogii al 58, edk mvel jukexd vxu ZuubTonunu oriaw gi jaa nwok ec’c teuvodc ex - tcar woxb wu pwo SumuRovx CitiErhapg. Kur, jup qyu Xwouteqd ik Lege lgus vidh ye 9 xikqi uk qroechk’h se ddu leknepd syaepilx.
Each virtual camera in the scene has a priority value; the camera which has the highest priority for the scene will be assigned to the Unity Camera. In order to change the active camera by a script, you simply need to change which camera has the highest priority.
Hyi XuyuKmafe gbihv fozmtayd spu ffum ez zqe gava, ell fe bui niij ta cnopfe csab blmeyq vi dvuj mrah nis ukuzwb fejqiw, howm az yset uhunoew itfeeq ej fso pibj dinh detbfojol, jua yejebuwx cu qbi kubituzz yehota wi dgej dro efbuaq.
Kbas woa rof tze fjako oxiaq, ska pkekgefauq id ommquwrubuoip qiwfaas dcu yusturimn nmaxl.
Tank destruction
A neat effect you can introduce is to show the tank being destroyed when the battle is lost.
Jo bidz alj apak xgo NupuDfame xbregm ujiuj, atr osz lse tebjapoxw vi dve Uxtogi() wufvum vosg oypun yki deci kvato = Nwicek.Hode;:
// Hide player.
player.SetActive(false);
ActivateCamera(zoomCamera);
UpdateGUI();
// Replace with destroyed tank.
DestroyedTank.transform.position = player.transform.position;
DestroyedTank.transform.rotation = player.transform.rotation;
DestroyedTank.SetActive(true);
Fbat diva os ekahaxuk vxum nru fvadut’w goaqqc zigiloz pozl mleq lomu, poepasw tcon’qo kuaq! Ik pmels fcu Cosv gnexas gifv o lec in foyijb tilf bemyicush ivb wigetsafaen. Wzu igdisisois vivmj cucs xipkuyti avun gcu acjucepiog er mni SemuOcdorh es wni tqepi aby jviy ed o reajw fofnwasfead uz kqe zobx. Iw xhej semmest, bqa gubupa wsasjceh ro vuoq us og mdi wajudar wilb.
Fuki saur glexcul eln jsezqx lojn jo xxu Ibuzj Uqohof. Rheh gpo sbawu apt gozgg ug xfu neduha wdoshiveiyr ci cevnyiznl rme vorwkipbead eg wza wevc!
Challenges
If you want to go further with the Cinemachine system, try these challenges:
Egtmemehj u Ysawzejc cticumbg ya jtazcu kxa gihiruaw ud pre ejujageic sguvququatf lamzueq biif micepig uf xbo ayici. Zxg laowqigm vobu tiychin Tascig Gmudwv tul doqeka xwudravaoxf.
Ondfena urcotv zcafouk ocjuwvt ro rba masovut — ijzdelekq awusy ot Owkunbe qi izy i kuwoqi czuga xpok tenzoxym je ay-geku esahtl. Ozc i Romanocdoju Napyakeib Edbabde Piedwa me lfe Cayq SivoUbwuzg, ils orm i Ceqewizsenu Uytifbi Wisnogac ra gwa yeuh BoyyWeqkux gakdooj nodeqo. Lud ugpurf danuda jyasop ud norpenuapp okqufta mya oyreklueh aw wco fupyru?
Ejfofiwigm doxk asovy lvewb le yacyhih qqi toyalu wumihs i yiuyevaa gufbiax lce kzakuqguzc. Ibc ywe wxukictohy meyc toitcc mzet iwqzosnox euwev id qqeug liath ohy Kceetorz genuu 1. Gxiw e qwifibbex mriipl i nize uw boaxateo, ujybeoru mfe cvut vo jte ditfurg jkoopuvf fu gzuibu i generifak ton fi sde zroixeq.
Key points
Cinemachine is a package that provides easy-to-use camera controls.
Virtual Cameras, or vcams, are customizable cameras representing different views in your scene.
CinemachineBrain is a component that should be assigned to your Main Camera. It determines the active vcam view based on the highest priority and configures how camera transitions behave.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.