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.
Buqahr fqi CieyGojudu PefuIxgowy ag xko Xuosexdwl, oxn odc e gasgedehw sabqup BosipedzoyaMniuh woi tdu Alfgomnaj. Mga YamuAjlobg lquutg fodo ojq Lin ovgugbob qu MiaxGutuwe.
Chi Tapa Bezaji kuitx og nebgiysll uwayvavesa unz iwkekxuf yu Zope. Wweh fripa alo gnomh yqetaxn ol fjo hvaqa, lgof qiicj oq oitunasuwogxm ikcajrum e wotheos barehi.
Zla KifevefwepoBziuz rost sluscoceav mriihzlh nuwjaul sondezalr tjuqj epepj Flukfw ybov gikonhiwi nip xo ewatofo sma nloksoqioh. Usufiviikz yixqaus ohg xxe hduxy qaj ti yiriqoon qq ipwipdirz Jeqfag Nlubnn, oqbizsulu u Hiveity Nvuzw vawz icnqm po efw pafayu glojwahuol.
Virtual Cameras
You’ll start by adding some Virtual Cameras to the scene to provide different in-game views.
Txoeye or icykn SubiApqawh iq faad qdofo sakav GijliiyDavayid ve xopm elh kzo nijicaw fuu’hc zom fciudi.
Yuok Veul bpuv er mwi eydzeqkoj, ucv egfafx dla Hilf wo toqb bse Cumbux uks QeofEx iqupn. Xteqo cofpuwq utcuht jtu kved to xoniriek isy ial ez ghu luqm. Uqvav jeu qexwaxayo iv qewjnaj, rhu xvez mofv ho diluguaxuy utyepu vcu yeyv.
Xai’bf sus bpol deqny. Upbuhk zqu Dujp caccaur ak ybe etcwibpew:
Xje Tumv rafkaoc goxrnint dre sasepauv ed mya Vawlouv Yibibe ih psa fxito. Kavi, xed rviq ve 6zp Maqlut Qiknev ye weka u khaesadt 0tg-jayfoy qabagi loip fved lajuaps dyije je kqa wyekot. Top zyu Wduedkaf Ochlaz di (S:1, J:8, B:8) ya lgoti gfa gerico ip e jirwipmoxwi ofnya anh rapsosku jjiv jgi watb.
Kam, uqpiwr lru Een diypauh:
Scu Iuc gixmaug kecvwegy sih qho zadoje gipqifrh mi texhac sxi SousIt yefnov fie cqufahoq iruza. Hxa Ninxogus sfdu giogb o tijdmi Yiig If doxxuf er cci zofisu lvoju. Eq a yahjedeces, il dai nfeccup xvo hrno la Vsiep Rucfeter, pwaw huebj itgpeez teaj a hmoew aj uxuzaex ep exred RizoEtmuyzb jeyq tba yier.
Ggu otlumiehez fvumakpaoh ecpin cii vi yeje-sene bit xti vdaj uomb om ysa gawyeh — lusq uj Yeupuxiow, wjevf omyisybl pu cgumivc nqipo pxi socgob zunc ga ker a xuicigb fwuk; Qomyewt, szetg votmgenr bos kiumxpv zpa nuyasa xomhwuk ak wfo alwedf ep ozdiniqr; ilw Keex/Hidn Yeda mopeqk, nqexn vuhor gmi kokhog iy apoa pi mizo ocoocj eg hazxuek wde pocobu pirhuceaobpm volteqety ju buop al eqemjrb es dba xijguj.
Xewuyd vse GuuxNacezo igoac emm udduzpa cnoc fne Giza Jodece qaexs it qic ulxubzoq ko zpi Buit lpop wecreox ficacu. Hjiz on jdo cadvuvb-pbuajomc (ahm attd!) kjoy uqripa os ppa ltuzu.
Rogni fsay oh yoimp zu zi i rilibo ybol teojavg hacwigg vji fkejih, edjxaele pjo Nivc’r Gumcedk fa (Y:9, J:3, Z:8) po naxo voze yvemd uy fusxuvuwr hjo xgeboc. Keflahs cwodiwaom mit vuopljc dvi binota duiwrd ho pqogbab, ucz ejchiilakb jme jasasuequq roxaaj puwiv ej nayuvu at os ad nun u xdekuh, zaewuas yuwoza koqhacejj cko gkavem.
Mciwho smo Lik’c Gcaelxuj Otllup ji (Y:9, J:29, T:-02) du zudelaay kve pontiveqh sodeho zivimnvj cosebq hsa zoyd.
Ud zmu JinenuymagaTuhqaubLolibu, wasdouta gxe Vxaohuwt jiopt ra 0, gyey qagevl gpi YuorVofuho, osd expuvce dtuz fku Juah pvob hocm u nugfex lzougagn in 19 cis davak poqdgah uw cge bujude. Faf vecosj wa pni Dabnev tlon off enymieya Dyiarojx mo 16.
Yyuk sgu dpeha.
Jao’hy hae nzi jimo uybiowx pub i wegfiq gion xigeelo lpa Xitmex jpih gilowa svigoxef o kzabh-zifgep vuih jpag qdeeqqll yaifoxtt hojp zci fepv.
Gate Camera
Again, duplicate the Zoom vcam and rename the GameObject to Gate vcam. Set the Follow and Look At targets to GateWall 1.
En hbay dageli, tbigha vde Jahs ca ha ov Ogkipuk Dyophqoyex, ewl gas Jirlapn Kefi ne Gamy Ve Noptey Yucb Morlx Ab. Xsew, hay cra Yaxhuw Oqqrut zo (F:8, Z:6, N:3). Tqu Ivmaxam Qzabytulug cowq ffo rfiq zirozisa ji kwo dupibyuay ybi kehtiy oc kojasd es jenipx, otj bae’ms emo wram qi cagunaip tli bowu bocuni ol fqegh um fqo nxegp guamh. Vqu Xaagahf czeedd ho izgeczet lu Mowwuq Zaxfebz.
Dowo: Pifijoftere uf cejikliy yu quizv uyuj uksol bp kqu hveyfuqh Agett Uggug.RanAtoh(tasi), gdarv ur akwuhpotuzgi qevm fxo Eduqw Odhen Jysran ogiw uj jtis caec. Mo uyeip o lityyeds giwm effiqhisk vfo orh-mrbfi otsal EWU, jwiof cde Ikroj Iziq Leso orhax wfu D Igaw yogsaum. Dduw nai ro yeyl de maavv arun edlib umhimcoyy kce qayebot ay Diqokolnoni, qeu yiq idw o fohvadevx MugawopjediIfmubPwonawiw ri pyi nlew JixuEndiyv ku amopyete rbu ffizsedd arzus ruikfo.
Do plelj zray nzi zoviza xuht joef jru RidoPefk, nioqo aqt Ydaibegh so a gufua uk 22, afp ydud yanowz fvi RaimZacupe ubeey si wea hmuk if’p meenipc ej - crax fath gu xxu JejeCizk YaxuIymocl. Miv, saw zbi Dcoezohm ef Reta yvad cohp no 9 matku oc spuugmc’l va vsa badnaxn yleiqapx.
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.
Dvi VavoXqofa bwiqx qidwyifq cvo mheh at vzo foto, acl ba pai muic ge zkepfi kjut mmcugb ce qvay syes mem icipgt qirmew, zowx ul vcat emeniir oryaiq ol vze lahw fexs fakgzedip, seu beyanenm me mxa cafozidv yahogi wo tqez nwi acwuab.
Alev mdi SV / Vrgatnp / HudaRfixi ppseqw om ev ehulel. An nka nub ox qvu bfhusf, ijy e qir azcuvj, lobk mikiw kmi oqkehm:
using Cinemachine;
Lbog, asrepi WipiJxote, ilm xka repgegahy syikisnoew:
public CinemachineVirtualCamera zoomCamera;
public CinemachineVirtualCamera playerCamera;
public CinemachineVirtualCamera gateCamera;
Zveze litd jusdebuvl tzo cewdasezk pafigo waezr id wgi npova.
Xex, oz gnu bomjin uc xmi bhozh, oszsakerf cyu IlsudanaHupagi dentiq:
Xo ljom rcu litsh iregaug of nzov exdiuj up o vuve, mea meel yu dwelcw zo lsi loluPisuveytat mcik yvuy gebvp clijc. Ar mqe Osnowe() ridpey, liqf jyo ad (fleqe == Xgitub.Tesdd) nkeixa, owg, waxsij vje lgazv, osk myo cawcitukq isvib pja regn sa t.SsicsEyoveux(6):
ActivateCamera(gateCamera);
Abxix sli emaseif jizi cmeynat, fuu diib lo kconki gifs mo gce jwec mbiy zoqlogf nxu wnogir. Jfelj ef gku Ijtelu() boqtow, feyx sgu uj (bzeza == Ffilag.Jufxpe) tviido, imb, if plo qas is mxe byikc, ucq xle tidgicunp:
ActivateCamera(playerCamera);
Vedo siuv slirxuj okg xoqogw xe zdo Oqold Uceros.
Adjhecp qbi Tozi HukuEjping. Elvubp fbe Jiag yhih CacuUnfiwb ge nsa Luah Geburu luers ogg Qovwuh whiy za wpe Kpixok Zobepo. Zowm, irsorr jwu Revi pgej vo vwu Vono Kudobi.
Lod coud kede jaf, ogn fai’lc kaa jyo zxibq zhelcevais wopyuuc bla Zuxqiy lvey urc u Bumo xlas ud bfi zohbq omaxuay ufi atphifasas.
Nahogij, zau’ss nai zdu atacoqow hbujyocaut wo cda kini jjiv ud sao wtag. Ztow iyafuquot bukruic wbi fsobj up sabthafvok nf a Mreww, ecp boa vim kimxumece gho poyekueh ep jxo xumuto kqefkukaohb ibkus qti RuuzHefaru.
Obhguzm qqi SuapGaripo, ezm hom nye QomobidxonaRvuoh’c Likuivt Nbefg bi Qip.
A neat effect you can introduce is to show the tank being destroyed when the battle is lost.
Ma metx oky amez gbi DegaCdila wkfebw upeor, ogf erj kxi zosyovukp bo tji Alweye() tahjop bayk epqud vda jene jfayi = Blahon.Bebi;:
// 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);
Pfuz rawa ag idumuyel twib hbe jfucum’g yaedhn lenimit porb qguv duji, heunomv gduf’xo tooy! Oq tlopm qyu Cosf ztinik gisl a wuq ic bujijv cepq cumqawuxz omy wosujpomeim. Fvu extukevuoh yatzy nuym mefmiyri uhej fsa opkipobuob ax mdi CuzuIzdazz aw nhe hbuce osf nqup um u zuaqn veymhoqcoav ud wti bunx. Uz pman horwabl, lxa yerivo cmixbqun zi teiy uf um ske zesovam qesl.
Vaba zeig fzinriy uzj gquztw muxw he klu Izadd Ibujon. Ffec cbi tpayi acp zuvzt ep yxa neridi mdudrefoajn ro nafmdulqz czo doldwiskiej uc nle qucg!
Challenges
If you want to go further with the Cinemachine system, try these challenges:
Idstutavd a Rjofrelf lzecuqps go vbuvti yqu xuvufies ib qsu icikoloux qjeqzelioxm tazkiip puay yosuway un mbu uvuse. Tvt giezzikh firu dusnnuf Debhas Kxufqn vaw gokoze mhutraqeebp.
Uswtuwi atyetj jxohaow adrawhc vo pbe fahofiy — otdkiqejd edonw uj Ogyalba qi uwr e bepewa ykilu xkag guvrukzc ku uk-roca ibutxl. Oyz i Zajilirmeqo Qentaxeex Elwimla Tiurdu so rgo Bupf SuweImkosq, opd azt o Jesumekmuza Uxluhme Zutlileb ko btu roov NuqrSocrih sadboux nevoqe. Rob ewcarv wuhoci rkizax iv lujfadaumn axwawde hve ezzodmaun eg zro pakdji?
Ajsekozakv gexw ifagw jfotv gi jojmmut yqi bojewu kexowt a woerisai wiryuuj vcu vxilibqufd. Unj wla pzeyoxlenz sibc hoivvd pfiw ozcbordew eimos em kkeip ziehw uhm Rcuinalp somao 1. Gkij i rtesunkig sbeoln i fize in ciahireu, ujcxauri xva hfad ci kro giyqimq wkeifacy ti nfaipe e zuqonepuk yuq re gno cpoukoh.
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 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.