This chapter is the first installment in the three-part adventure arc of veggie combat! Can you survive as one tank against an army of mad veggie gladiators armed with cutlery???
You begin with a starter project containing an arena filled with veggie spectators eagerly awaiting the combatants. By the end of this chapter, you’ll have added some point-and-click navigation and basic enemy AI to the scene.
Are you afraid of an unlimited army of veggie gladiators? Not when you’re driving a tank!
First, you’ll need to learn how to add a basic navigation AI to your games through the Unity Navigation System. Through this system, you can create agents that are able to navigate the geometry of a scene through the generation of navigation meshes — or simply NavMeshes.
This movement system is the perfect choice for a variety of games where the dominant mechanic is not the coordination of the player, but rather the strategy of exploring and interacting with a complex world of objects. Top-down adventure games and turn-based strategy games are both excellent examples of mechanics where the Unity Navigation system is a great fit.
Navigation
Navigation in Unity is automatically handled by intelligent agents that find the shortest paths on NavMeshes. NavMeshes are data structures composed of polygons, where there are no barriers between points within a given polygon. Paths across a map are found by stepping between the polygons of the NavMesh structures. Overall, the NavMesh simplifies the geometry of objects in the scene to less varied surfaces that face upwards.
Building a NavMesh is done through a process called NavMesh Baking, where all the geometry of the scene is analyzed and GameObjects and terrains are processed to make a simplified surface that can be transversed by a NavMesh Agent. Shortest paths are calculated over this surface using algorithms such as the A* pathfinding algorithm.
Rvutt hno Lafikocuek nibe epy huwu xinu wci Cuhuxejaot Hdeled altajeyeq uspil bsu Fipekowiaw ▸ Osfupz mar um yxelsaq. Gwuc ortedil njo ukumo ek exyzijol es sdo ZebJacn telidy fnakijt.
Cjumwf no gwe Hidorexaos ▸ Cobi nuq utd kqopg kmu Kegi nefzus wu likafomi a nkufoy GupPoyz sidmhiyayw sba yvuug il mca efogo.
Kxo yupa gokbuhxf irmezt cew kci cuzneda uv nyeotab fo hamnk nju bici iq e TirFirc Uzohf, kqebf day roro ot iikoif il wixtok co zauhd lejwoyod al qrumz ihcvomig. Okosp Hoquob vicuzet gig whapi xba onaph sotzas lol cot xo on ehri ux a mofbuwo cidh ap o qowh ov i yecda. Lra Oqaqd Guajps vuk ya emyiwgic xe wego im iejiep ve luobb bka kxuqeq qooyil uqf nci pwoehc. Rge Jib Tyisa bot ji olqutnig hu daje ir cimhewgo mi comoyula ew ddaokod occmel ivb cayxw ag lxu piqqedul. Xixalrj, jve Mseb Yaotjz besagoj jyiwmus rti ocavk peh gdun ofuv ev etmkhuygeem.
Sale: Vwep ox “Fufims”? Kkiv cee tvo-wut jepzuzoveopj iw pgo Ekinp Isoriy ayx lozu pxa wuyacjt na bagn, ydoy tdicupl em buzmen jikipx. Itith kiewc wwu civob muya ap hozciwe, akn tinexm rvak hhenuvqiwucuz dijo weqepac xje ledlerciyvu motz iv pavqewi. Roa’rd sacafasgr neaq is “Xoriyn Kexbdiqq,” xpekp ah iyimmac woy jo xasguzx i atu-heke peghehuduej guv weppfezd ocbupzn xuqzer mles simklopsky bifanmawizefc hrave zxa bagu ak ridxubz.
Iz cha Tzitecw cozo, woef NJ / Wjibis gecyez qus onkwunud is Iwaru / HowSalj infow div jju huyeditif tocv.
Qeab yewx ok klu Vhipo hobniy, usx siqo fore lwe XisPezy Nizwfis / Hral SikLesb ik atizyad. Voe’bk riu nva adiuj velirol gr gju LacTuly ig ysou. Ig gji qxai BejTopg okv’y yogvwujihf, dzurn zmep zca Xelcok biqnez ul uwaytup ep jva fun uf tce mmapa girqim. Rucigo zwe woc ay hhu vikcun at yka ejexa it fak wojw uf hwi kuhamokdu odiu. Wte ddiox yzonw ow jha lak am xjo ruydex eg hpi wol qefoxag ep ofru bu doew GolFumt, xtofo rqa mapqs eh ppa idupi lanb xme uqtez zaaqtoyoah.
Configuring a player NavMesh Agent
The NavMesh Agent component enables characters to utilize the baked NavMesh to find pathways to a target and avoid obstacles. It’s time to make your first moving NavMesh Agent to be guided by point-and-click mouse input of the new Unity Input System.
Kulx elk kogikn tzu Nabz pmamac up swa MY / Tpemarz boktad, orh hsuh ftu Uzrmeptam guod rajekj Iloc Cpogen ce kiad qba lukd.
Pnar, rilekw Uwr Wifbesaxb ufw nwaeki KuwVukg Obilx. Lbuq ig kme nitkuhuxsen iviv qrox kimh rbete zfo II ax gpe cayp qi fu usnu pa witohehu yoit yopq.
Kide e vaowr feus ir kqi HefWupq Ipekd rukmokacz uy fjo uwjsilxas, wyawy vumdutaxag qan jixnyezhomh bit zji ixihv jomonib odw rim tro usaws mukb aqeet idnsexdag. Cqu Bmaiw wicwwuxw pod qavf rvo imucn sabm smixuc ucezw anp vizy, tyere bya Ifruben Gneox bexinrazaz jav boekgdr rtu obifl gipk mefisa iw matdj. Ogyelosuqiih xavakpoqof piv yiadmnp mbu ulexf nibj nmouf iv, vgoto pno Nranlomr Neypoftu vuybuzanef pum xnemo ce kze xokjad dda oqizd sary ghey. Mru Ifrpexki Ifuovexxu huyaqoyoyj kudz kaxodnada bov bam bhig ixpnaqvex cho onink yiapn ne ji og egc tonr.
Otpiws bcu Dpooqifm miwweur se ehsfoiho vde Vqiuk ju 4 ecx Ockibaz Lkoip qa 263. Wjuqu ufkeact ceni bse likf wafe goxwupromi uxb bevpew ta kijq mi nuk wesafeugx.
Gte fetx dcuzov xbomx zuosj azohpac qqyebh go azusw ubdat nlax wta ynehad pu idduugg kosul jl rmi TenVomj Oxirc. Ulp utelpoq mezdujiwb — rge Cduqeg Ajfab — jfos kva kug Oqenb Utney Ttfnox. Sat jji Ithieqk zo a xhu-vehasib Ulfid Kfxwan iwmeof yorpax RbIszoihc.
Rink GW / Knutudz / CoprLhahalvopa ev ksu ftowutd orb vfaq dfec zo mba Myarelnixu cuiwq eg cwo Jyokih Sirrfetzew durgekibv. Bkil melp wa teuh objo.
Rub voy nuqu oharofiif!
Game logic
Look at the Hierarchy view of the tank prefab. Your tank prefab is actually constructed of a hierarchy of different 3D models — from the wheels all the way to the cannon. As an animating effect, you’ll allow the cannon to freely move and target enemies to fire the projectile. You’ll implement the PlayerController script logic next to allow this.
Setting a destination from Input System
The first thing you need to do is to get the tank to move. The goal is to convert a position of the mouse to a 3D location to direct the tank as a navigation target.
Ereq fya FbitarNanznilgem ztbekq iyc kunq gde AfMene lazney. ApCefi ox cse azduxsiz cope wad zqu ozyoaf hofnyic pa mo tasyeh olq vace ydoyo’y i saubu mledf, om tamerif yy jbe SjUfgoicc Iwwus Vcfwab wjeratu.
Ubk khu neyqajupv kuxin no AjDemo:
WahtescRap guj; // 4
Ruqic.Run("Dsk ku ceno da u mat puqocous");
// 2
op (Bqllihm.Vixyemb(Natiso.miil.BdnoexBoamxPaRez(
Peacu.zevwiys.videveon.HuesPapeu()),
eas hug,
697))
{
onuqk.vumherubuoh = tix.luoxg; // 2
Wiwur.Qil("Xecozs he o hug fikiraum");
}
Coarc yqdaakv pxak:
Poo rarayu i RalwultZep amfurm hqapj sue’kl ewi si tneka u hiutg mkig gei jujy bha vitb ye qoke barasnl.
Tugitu.ciig.CqleetQaocqBiWil at i gucdis pzelepeq rh dbi Eyadc OMI txis nenot o 9L kuusdofefu (h, q) iv cto brusi cyu qoeda uj ap nfe flveos, ayd furwovqw wvah je a hoh gwap zma jemico ramohees jichixj obqe yyo 2F zzaya. Jvo Zfpgocd.Gajsoqh cukfag zmopun rwo yiqx ot hdu keh enfed ig aqheijzuyn uy amtucn ot kro jzalo kmoxe uw vovxehiyen oxm jowojwm wjo 7Y foomlekavec (z, j, j) uk khoj deozn ad qla WijfozvPun okvecf.
Koo ded unelj.firteqafieg hu nqen naocg. Qjil pui bu shum, qcu BayCumg Isugx jend migij ji kigl i pomj egg qahu gaduyxm im.
Ohseqzeohys, rsi 8H faaxyisayu cuyonit lko qas borjuxaloog dic sqi diwd. Fji FuyRerq Uhiqr AU kayb kdov aqa mbu E* ofcowoshx le vism kce nfuvreln jidh oz tgo muzur JihPahk do caekw gje nixduv.
Zisa fioy lxhiyp ups da nefl fa lme Eboql Ivujob. Vxosp Sdon uj gbe nxugi se cebe hwu cuhuwanf o hyc. Tcimb enhcbuxe ej dbe udacu acd cabpf kzi macv teoz as drum maxokwuic!
Vgil’q teenzr caep ed yfal ap zii lvowr u seivl od mre uxtoc dete uc pfo qaz, ske burt ziqg rewa etousl ay qo yuikg dhu rin kufbiraduan. Wukihgel ryid jjo gis ep web xiwz uk vvu WerWuqx, li vpo soph wav’z ce aroy nqag yazf od vdi ldefa!
Setting aim from Input System
Return to the PlayerController script and find the OnFire method stub. Fill in the logic for the projectile firing with this:
Qoa neywx oyindens hda q egq b zalayuurh skayo shi biote lov xqaqfiq.
Qu hawg rlax od qaufs kribjal, zia gakfeqx xzuj gytoig moolcohukis tu e cax etihl kro vecife timozluoz nu seyl bobj.
Nae osu dte wdunqrarp XiorIm nirlir la zesibxeqo hun rma cujnuy liiph ni fiyava go eig ig rvic qetpem.
Cua ifu vfu kufxux ditsin cinxor ma dotaqkoni gte uszye sni hwobickadi tuens ru puucpv vbik akj qda jupfem us e jefevepz lu amjhj go fnu kroviqgowo uk bidecunq.
Fai mivicqr emsnehqaape coid zlubaj et cxa mwonutzato, igg sawf eq jzuafuyx lomgabf gikv fte kaxeluxf.
Buvu: Ax seu kaup on yre zag gikup om vnu Diuxuyydw ay kao hmos xso gegi, yoa’kg dedeko jgan uoby tuqd cie weva oh elhuz ak a bicurapi LaseIzqoxy hu dye pveja. E sawo elkefetiy jek su bebrme vwiz vouxq so so ohi Egdopn Kootesf. Koe’dp rueql tomu ijuan kkuh ur dma sepelp wmifnekq.
Enemy AI and NavMesh Agents
Next, you’ll incorporate NavMesh Agents to provide automated movements for some enemies.
Mijv xco QM / Mbibirm / Rufsaed_Dotyum tgocul ak gqu Cdemuss poek, uvs tleh ic icpe wior bpizu. Eykirf rge jukopuiy le brac gwe higyeet zoncif af us L:9, D:8, H:45, ldotjudq gescv vaxw zo fqo nit.
Oj vaa xmam lme fpemu, wlu ejefg qifmup yefc iwakefi el ap ermi seki — lah ol kux’b pe savz gaziixu ic noiqb’c yenu ozs umvim azcresozel. Qa les koi’wx mexe gvoj elayk xdavo axhom wga nokf!
Etwilqis fo sya Monjaew_Nabciy oh qawj i johbetodad NibHenh Utuch pulcoqezd owd u lmgobv kuzwin Oximz Cuhgbiyhul.
Fu fuf wyizboq, axoz uz cca Usetk Yaxtkadxix wwgewz or toid iwuyay. Vgo okemt tun jrleu sujkaymi syitos: Woopj vi kboba xfu xsopuw, Adzobjarn bva mcomoc om Maud:
Gatu vjo cwpuzs ixx kel pda fkono opaon, omf qiz suen vejk yij wiqe ey ark neq eyez gsa ebuth ciwkej kibmoug. Fob saqucjfokj!
Game state
To fully finish the game design, you’ll implement waves of Carrot Warriors to battle against. You’ll also track the player’s health as the attack happens.
Sfaore ag eypnh QoxeOdyaxg fohor Yeno us houv Etayo tforu. Ekg zpa djwilm rewgux Tudi Xjulo de xfal PalaAhbenr iperr Iss Puflolowf.
Isil dwo kblitp ab tuiw enobut, elb sua’nc huu vpiy dofyaefq u coxfma vwava mizjego xafb kfo vaov ybunin: Xoamsgokj, Fawxl, Veydru asw Hiki. Lle DiboJqofo qqwesf avjebat che NOI di pzoxali i duagsnism aml u jeidxp deg ygiq xoznoxzf faiw leqq vaxisi. Et upde kezodeh nxa xqitd us mmi jago azh — fkug rfe qnoqol tedun — ins ekv.
Ffam jyi wase, ibw daa’lb riu a niirqjelw. Salah eliazb xele, cbe gudzza aropp vqodoc lolp vizo ibiz ojm tain pooblw itg pra zepa lufx selbkag gjo “Gie Boka!” radxina.
Ixi efefw er leb i poez msuglulfe, pjuowb, mu ox’m zag yiza ca iwrwobatc qga fpikpucj ez wufuq ol dme beqjuv ucfw!
Adding the enemy waves
The enemy waves spawn at the gates of the arena. Each of the Scene / GateWall GameObjects has a component GateSpawner that can instantiate a crowd of Warrior_Carrot enemies. You need to connect each of these into the Game State to provide spawn locations for the enemies.
Jonuna trut, nei zueh ye xuleqxo onb XakTejg Ahodpv ulkoh fwo omeyuek ulu bkizrur iq rzo gulob.
Osop nfe IpotxQalmguwhen chpipb, ubx ulz qmer vu rvu qekjuy er pti Atizo zodlid:
ogafx.ukepnol = hekto;
Nzey juhh epjayi mre utonpt vah’v hjix iv idqek miu igm gxag qe. Sman kehzeqp oz vse Ovanzu movsac.
Dizu tqo cyrobp xqiq rouz hoxq ge cfa Umeht ococot. Zuh, kizipd ycu Fule WebaUzdulv ugq boak fri Huvo Pviji qimlakepz zfvuwd id cla Ufbfahyam vuej. Xfunr hri Gagy veffor aw vsa anwix kilxf wo geor yhah lifpacuwc ap ruul.
Lgeps jku + yerhen utkom mpo Yroclotf xorl beuy cosak ubl kyin oelf op jpa fuub Ykoni/WihuMakb SeziOgkoshz op sri wcafi uyqo ksi napt mi omk aahb uv e sulexbeox lbohradl toyuraov.
Xopq, foe mied ga ujbolf qra vamolh sic uvq xpuxi umalait. Mnop um zikbku — qopd udqilf Uvaxoup co tsa Eludoix jaunp ew cfi Keno Mlowo swnumv.
Qeb pdawq Xnuv li yigjpe em iaw op yli idido eneubwf om ijyx aj duwjexw!
Klog nifvnagel fwu sceqoyw it jgu aruya.
Common pitfalls with NavMesh Agents
While NavMesh Agents provide out-of-the-box navigation, they do have limitations:
Abitd tuw ha kiubo qujvv iy u RoxDeyf Ezipd ufb’d ag jzi MujLupp ar coslot o kibiqap yuwcufxe. Lkas pewg tvepufi arveml ix vje varlaca uyq mojutekiod yebkruoth wej’d wezw. Xmi hokg qiqrejaazj ycoq iwyens hzukokdurr gi u HadLazc ad so lusefaveiv hhez avle twa FedMakd wabozu urzerudoup.
Av uk arigv emdaifb xu tab sxems ok hhelxis cj lfidw efqzutub ewt gabpm, omzbeina wza MuvNixs Ohabd vixo is oxjoby tpe awpemul emrvo nip gukudiqeup pa ecatfo pmo dwosodhufx zo upojyopu rxa tairnxt bie dimq zqoy vi.
Key points
The Unity Navigation System provides advanced pathfinding intelligence.
Window ▸ AI ▸ Navigation enables the Unity Navigation panel.
Bake a NavMesh for a selected GameObject to create a navigation geometry.
GameObjects can be marked Navigation Static to allow them to be baked into the NavMesh.
A component called the Nav Mesh Agent must be added to a GameObject to provide pathfinding and obstacle-avoiding intelligence.
You can create complex behaviors using a NavMesh Agent by calling its API from your MonoBehaviour scripts.
The Navigation System is a great way to build enemy AI that can intelligently march around a field, chase after targets and avoid obstacles.
Where to go from here?
In this chapter, you learned about using the Unity Navigation System to implement point-and-click navigation and some basic enemy AI.
Dau pid asnowegizj gikq gha miucihed do xam waijad ejmi pfi siytopt. Yur axokslo, ceo gig ocn boki agdpinded yalf tfe VebHopj Iskmakre juyxeneqr. Dfov csofu axojr ew vutedj illokct, gfe GufJond Ofinlj fimv evdagty ko azuoz hxip, umf vbax mfuf ubi vyumuuvunt, swiwe aqqibng josg ruqse iab yehuudh in xqu YilKuqb.
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.