Hetalkedaboutmatchthreeandhowtoactuallycalculatewhatgoesontodeterminewhetherwe'vegot a matchandhowtoclearblocksandhadbetweenthingsdooperationsovertimesorthis a synchronicity.
Theyhavesortofobjecthereontheside, and I believethat's toshootcubesout, whichthisyearis a cube, whichyoucanthengrabwithyourgunandthenshootitthroughportalsandseeitcomeinandoutofportals, whichisprettycool.
Um, andwe'lltalktodayabouthowtocreatesortof, ah, simpleversionofthisandprimarilyjusttheaspectofhowdo I create a portalthatlooksoutofanothersceneandseeitupdatinginrealtime?
Um, andhowdo I tell a portandgetbackbackandforthbetweentheportalsandcarry a weaponandthenshoot a raythatwillactuallyplace a portalwhere I wanttointhegameworld?
Sotoday, someofthetopicswilltalkaboutsooneholding a weapon.
Sowe'vehadwe'veusedthefirstpersoncontrol, andthisis a veryeasyandsimplethingtodo.
RayCastingistheactualshootingoutofRayfromyourobject Z directionforward.
Soyouhavean X and A y, whicharesortoftheangleatwhichyou'removingaround.
Butthenyouhave Z, whichisalwaysifyou'reusingvectorofusingoftheforwardvectorfromyourcharacter, it's gonnabeforwardfromthe Z axiswhereveryou'relookingeffectively.
Andsothatallowsusto, um, wecancast a rayinthatinthatsense, whichjustmeans, youknow, shoot a straightlineandinvisiblestraightlinefromthatpoint.
Andwhereverthatpointintersectswithanobject, wecouldgetsomeinformationaboutthatandthendowhateverworkweneedtodointhiscase, take a portal, prefabandjustlikefixittothewall, basicallyrotatedfromitsdefaultpositionandjust, likeputitflatupagainst a walltexture.
Massmaskingissortofhowwe'regoingtoachievethisportaleffect, right, becausewhenwewhenwecreatewhat's called a rendertextureinunity, whichhereisthethirdbullet, Orendertexturejustmeans a texturethatwe'rerenderingtowith a camera.
Soratherthanhave a texture, beanassetinyourgameinyourhierarchywithsomethingthatyou'vemade a photoshopyoucanactuallydynamicallycreatedatruntimewiththecameras.
Whatthecameraisseeingimmunitygivesustoyouforfreeveryeasilywithwhat's called a rendertexture, whichisjustanotherassettypeandthentexture.
Mapmaskingiseffectivelysortofkindofthesamething, a stencilingwherewecanchoosecertainpixelsofanobjecttodelete.
Inthiscase, wecreate a texturethat's whiteinthecenterandinblackaroundtheedgesin a sortofellipticalshape.
Andwhatthatallowsustodoistellitwith a simpleshader.
Decalsareisanideainthree D gameswhere a D collegeissomethingthatyouhavefixedthetextureorsomeobjectthatyoufixedto a surfaceinthiscasewillbeusingdecalstoactasourportal.
Andthenallweneedtodoisjustslapthemonto a wallwheneverweshootitandweget a raythatintersectswithwallandtheywillhavetheeffectof, um, actuallymakingitlooklikewe'reputting a portalon a wallwheninreality, we'rejusttaking a meshinorkindofslappingitonto a wall.
Andifyouperform a rotationinsomeoddway, um, therearethesethingscalledOilerangles, whichareyouranglesofrotationaboutthe X y and Z axis, andyoucansortofthinkofit.
I thinkofthemassortofbeingabletorotateandinterdependentLee.
Butthereis a situationinwhichyoucan, forsomereason, Unity's internalrepresentationof a rotationcangetmessedupbymanipulatingtheseanglesandsoyoucanactuallylocktwoaxestogethersuchthat, um, rotatinglike, forexample, inthiscase, it Z andwhytheybothrotateeachother.
Andso, um, had I maybeanotherweek, itprobablycouldhavedebuggedit, but I hadtoleaveitin, unfortunately, ranoutoftime, But, um, ifyoudon't, theinterestingthingis, ifyoudoshootthatsamewall, sotryandshootthatwalltheotherwallwith, likeputbothputoneportalontheonthebuggywall.
Sotherightwall, it's onlythatwall, bytheway, forsomereason, So, um, thatwallisofitsesonoticedthatnowit's rightsideup.
And I, forthelifeofmecouldn't ascertainexactlyastowhy I knowit's gimballock.
Um, unfortunately, I wasunabletodebugitquiteintime.
Buteveryotherwallincludingtheceilingonthefloorwillworkifyoushoot a portaluponthemsoyoucancreateoneupthereandthenyoucanjumpthroughit, seehowit's lookingdown.
Butifwejumpthroughanyofthewallportal, soifyoulike, create a portalinthehallhereandthenjumpthroughit, you'llnoticethatyousortofget a youknow, you'resortofangledattheright.
Youlooklike a lookbackattheportalthatyoucameoutof, whichis a bitweird, orwhateverdirectionyouwerewalkingthroughitwhenyouwentthroughtheportal.
Um, um, that's justdefaults.
It's rendering a um, it's a rendertexture.
Sothere's a cameraactuallybehindeachoftheseportals, sotheprefabis a meshwiththerendertextureandthenbehindit, there's a camera, andsothecameraisrenderinginrealtimewhat's infrontoftheportal, basicallyfrombehindit.
Um, andthereistthe e slightweirdwallthatgimballockstheportal, which I wouldliketofigureoutwhyexactlythatis.
Buteverythingelseissortofinherenow.
Itdoesn't includesomethinglikeshootingblocksthroughit, butthesamesortofprincipleswouldapplybecauseallwereeffectivelydoingontheportalissayingitisbasically a trigger, right?
It's got a boxcollideronit.
Anditsays, if I collidewithsomethinginthiscase, theplayer, um, I wanttoteleportthatcollidertotheotherportal, whichmeansthattheportalsortofhavetolinktoeachother, right?
Oneportalhastohave a referenceoftheotherportalsthatitcansayteleporttothelinkedportal, andviceversa.
Thelinkportalshouldhave a referencetotheotherportals I cansayhelporbackifyouClydewiththis.
Andsoifwehaveanotherobjectlike, say, weshoot a cubeintotheportal, itwouldalsogetteleportedtotheotherportal.
RightandotherOtherconsiderationforthatislikeifit's, ah, a rigidbodyandhasphysicsappliedtoit, forexample, let's sayit's It's goinglike 10 onthe X, anditteleportsto a portalthat's like, perpendiculartoit.
Andinordertoaccomplishthat, it's reallyassimpleasjustmakingit a childofthatthing.
Sothisisthefirstpersoncharactercontroller.
It's got a cameraattachedtoit.
Anythingthatyouparenttosomethingoryoumake a childofsomethingelse, it's gonnahavethesametransformlikechangeisappliedtoit, includingrotation.
Sobymakingthegunjust a childofthefirstpersoncharacter, whichiswherethecameraisherefirstpersoncharacter, bytheway, isjust a subcomponentoftheFBScontroller, whicheverynametoportalgunFBScontrollerHere, theportalgun.
Allright, SoRaycastingSoRaycastingis a nicefeaturethatunitygivesyouforfree.
Um, it's partofthephysicssortofnamespaceimmunity, partofthescripting a p I.
Andwhatallowsyoutodoiseffectivelylookatfromwhatevertransformyouroperatingatorwhateveroperatransformyougiveitas a thesource.
Sowhateverpointyougiveitasthesource, um, youcantell a directiongiven a vectoras a directioninthiscase, whatwe'redoingis, we'resayingtransformedoutforwardandtransformedoutforwardjustmeansbasicallywhereverwe'relooking x and Y andthenstraightinthe Z direction.
Soifyou'redoingiton a camera, it's alwaysgonnabeexactlywhatyou'relookingat.
It's alwaysgonnabeexactlyforwardonthelike.
Transform, notforwardon a cameraisalwaysgonnabelikecenterofthescreenwhereveryou'relookingat.
Andsoifwecast a rayfromthepointofourcharacteroractuallywe'redoingitfromthepointofourguntothetransformedoutforward, like a linegoingfromMarkPlayertotransformits, ah, theFordvectorofitscharacter, theforwardvectorofourcamera.
Wecancreate a ratecast, andit's like a fixsomethingwhereverthatrateintersexandwillbetheexactcenterofourcameraview.
Doesthatmakesensetoshoot a linefromthezealyour Z axis, whichisyourforwardvector, andthenbasedonhowyou'verotatedthecamera X and Y, arethere X and y partofthatdisease?
Andsohere's a screenshot, actually, whatthatlookslike.
Andsothenicethingaboutunityactuallyisithas a functioncalleddebugrayordebuggedoutdrawRay, which I'llshowyouhere.
I implementeditin a functioncalled D ahahcomponentrathercalleddebugray, sothatyoucanactuallyseewhere a raisebeingcastinyoursceneandeliminateanyambiguitythereSoyoucanseedrawRaytransformedoppositionandthenwejustsay, transformedouttransformeddirectionvectorthreedotforwardandthentimes 1000 justmeans 1000 units, youknow, fromthatpointandthencoloredoutred.
Soifwekittplay I actuallyhavealltheportalsrendering a deepergravefromtheirforwardtransform.
Andformygun, youcanseeitthere.
I'm justdoing a debugdotdrawarraywithjusttransformedoutforward.
And, um, usingmytransformedoppositionisthesourcepointandforwardisalwaysgonnabenoticedthatthezeroalwaysalwaysfollowingthesamedirection, right x and y aresortofchanging.
Youknow, thebackplanesarelikehowthat's rotated.
But Z isalwaysforward, right?
Andsothat's theThat's theraidcomingfromourgun.
Andifweshoot a portalthereandthere, I havethosealsosetto, umdeposits.
I canrotatetheview a littlebit.
I havethosealsosettodraw a rayfromtheirforwardposition.
Maybeit's your Y vectorinthatcase, um, butthat'lleffectivelygiveyounotonlythat, you'vegot a collisionbutalsotellyouwherethecollisionis, too, Whichisnice.
Theinterestingthingaboutrecastingimmunityisthatitreturns a struckobject, andsoyouneededdeclarethishitobject, whichwilltellyoualltheinformationaboutthehit, solikewhereitwaswhethertherewas a hittobeginwithandwhatthey'relike.
Andthenyoucallphysicsthatraycastwith a positionand a transformeddirectionandthenyoupassingouthitsooutisinterestingbecauseoutissortofseeSharpswayofallowingyoutoreturnmultiplevaluestosomethingsooutisgonnabeanobject.
A InthiscaseisgonnabeourRaycasthitthatwedeclareduphere.
Right, whichisinstructwhichrecallisjust a collectionofvariableslikein C or C plusplus, um, andouthitjustmeansthatnormallywepassinthesevaluestothefunctionthattheydon't getmanipulated, right, Butwepassinthisvariableasoutwhichwillallowthisfunctiontoactuallychangethedatainsidethisthishitvariable.
Andyoucantake a lookthroughhereifyouwanttoget a senseofhowitworksandmaybeexplorealsotheraycastthephysicsthatRaycastsectionofthe a p I justtounderstandwhatexactlyitreturnsandwhatyoucandowithit.
ThemethodofrenderingwascalledRayCasting, whereyougenerateonesortof, uh, youwouldgenerate a rayfromeverypixelofthescreeneffectively, althoughitwasmostlyjusteverylineofthescreen, andyouwouldjustlookupanddownforeverywhere, intersectedinthesceneandthenjustcreatedrawlike a texturethere, andsothatwouldgenerate a worldthatwouldthatlookedthree D.
Recastingisjustliterallycasting a ratein 30 spaceversusthesortofto D spacethatitwascasting.
IngameslikeWolfenstein, there's anotherscreenshotofah, normalsfromourportalscastingoutrays, and I wanttolookupandseeif I canjustfind a pictureofwhatWolfensteinlookedlike.
So, um, definitelyreachoutifyou'redevelopingOculusandneedsomeassistance, Um, maybeforthenextiterationofournextunitycourse, wecanhaveAh, a bigsortof V R dayorwebringinalltheguns.
Um, butyeah, backtosortofrecasting, andwewerejusttalkingabout, um, shootingarrayonyour Z axisbasedonyourrotation.
Um, buttheactualmaking a portalisprobablythemostinterestingpartofthiswholeproject.
Andsolet's goaheadandgobackintopresentmode.
So a rendertextureisthemeansis a veryis a basicisnot a basicmeans.
Itisthefundamentalwaywhichwegoaboutdoingit.
Andtherearevariouswaystoaccomplishdoingit, somethataremoretechnicallychallengingandlook a lotnicerthanothers.
I did a sortofsimpleversionofitjusttoget a sortofproofofconceptoutofthegate.
Butunitymakesitreallyeasyjusttoget a simplerendertextureupandrunning.
SoOrendertextureisrecalljust a textureimmunity.
Soit's anasset.
It's immunityassetthatyoucancreatethedifferencebetween a rendertextureand a texturethatyoumighthaveimportedfromlikephotoshoppergimpisthat a rendertexturecanberenderedto, andtypicallythisisusedforthingslikecamerasbeingrentedtoit, althoughfromwhat I understand, youcanrenderanythingtoitsoyoucancreateproceduraltexturesthiswayaswell.
Butinthisexample, herewe'recreating a.
We'reessentiallycreating a screenintowhichwe'relookingattheviewpointofourotherportal, rightfromfromitsfourdirection.
Sowecanseewhatwhatitwilllooklikeoncetheywalkoutoftheportalandgointothenextareaandso a rendertexture.
So I havesomeintheslides.
Ifyouwanttodownloadtheslidesthey'rehere.
Youcanseeexactlyhowtocreate a rendertexturesoliterallyjustcreateandthenrendertexturethatcreatesyou'reundertexture.
Thesethesettingsthat I used, um, fortheactualrendertexture.
Sowhat'llhappen?
Dowethinkifweuse, like a lowrez, rendertexturejustlogicallyandsayWhatifmyrendertexturewaslike 200 pixels?
Mytumorpixels, andourresolutionofourgameislike 10 a teepeejustlikeyou.
Itwon't beblownupbecausewhatwe'redoingiswe'retaking a mesh, andwe'refixingthetexturetoit.
It'lljustscaletofillthemash.
Butwhatwillitlooklikewhenit's rendered?
Becauseit's rendering a 200 pixeltexture, it'llpixelated.
It'lllookreallylikenasty.
Andso, inordertofixthatproblem, typically, whatyou'lldo, a smartwaytodoitwouldbetodynamicallyfigureoutatruntimewhat's what's theresolutionofyourgame, right?
Ifit's gonnaberenderedinvariousresolutionsuptofour K, maybedownto 7 20 p um, andthencreate a rendertexturethatisthesizeofyourgame.
Andthen, bydoingthat, itwillensurethatnomatterwhatyourresolutionis, itwillalwaysbe 1 to 1 pixelratio.
Wegointoourfirstpersoncareor, um, sorry, not a firstpersoncharacter.
Wegointowhatevercamerawewanttorenderit, torendertotherendertexturebecausewe'reeffectivelytakingtheserendertexturesandwe'rerendering a cameraviewontothem, right?
Eachoftheportalshas a camerabehindit, lookingoutfromit.
Andthen I gotocreateandthen a rendertexturerighthere, andthatwillgiveyoumostofthesettingsthatyouneedtogetupandrunningwithit, andyoucanassignitto a camera.
Now, ifyouapply a perspectivecorrectiontothis, wherebyyourcameraactuallytrackswhereyourplayerspositionisrelatedtotheportal, youcanaccomplish a muchmorebelievablelook.
Sohere's a Ifwejusttake a planeandweput a rendertextureontoit, that's whatitlookslike.
Itjustlookslikeit's justsquare.
Andthiscouldworkfine.
Ifyouwant a sortof a squareportal, look, youhavetodoanyextrawork.
Butifyouwant a circleright, youcan't reallycreatelike a circleshapedplainobjectthatdoesn't reallyexist.
Andevenevenitdid, itwouldn't beefficient, especiallyifyouwant a verysmooth, um, plane, becauseeverythingistrianglesandpolygons, right?
Soifyou'reifyouhave a circle, it's gonnabe a bunchofthesethroughfannedoutpolygon, especiallyveryhighrezcirclelikeoneofthese.
That's a veryhighrestcircle, making a polygonthatlookslikethatisnotIt's notanoptimalwaytogoaboutsolvingthatproblem, right?
Andmuchmoreoptimalwaytogoaboutsolvingthatproblemwouldbetosay, todesignatecertainpixelsofofsometextureasbeingpixels, thatwewantThioreadandthencertainotherpixelsbeingnotpixelsthatwewanttoreadandthereforeproducerthefinalimagethatgetsputonto a geometry.
Right?
Umandsowhatweendupdoingiscreatinganimagefirst.
Soit's thisimage, whichiskindofhardtosee, butit's just a simplesortofmusic I seefromMegan.
Soit's just a simpleovalwritestheexactshapethatwewant a portaltolooklike.
Um, andthepixelsthatarewhitearethepixelsthatwe'regonnarender, and