Placeholder Image

字幕表 動画を再生する

  • All right.

  • Welcome to G T 50.

  • This is a lecture 10.

  • Today we'll be talking about portal.

  • So, uh, portals.

  • A very iconic game.

  • I think most of us have probably seen it before.

  • The gist is you have a portal gun, a gun that shoots just these elliptical portals.

  • If you look through one, you can effectively see what sort of coming out the other one, which is pretty cool and vice versa.

  • And then if you walk in between the portals, you'll actually be teleported to the other side.

  • And so they achieve a lot of really interesting effects with some pretty cool tricks and stuff, and actually vow they themselves will be coming.

  • Thio give a talk on a lot of the technology that they used on the second so we can get a glimpse into their version of portal.

  • My version of portal is a bit simpler.

  • Um, but we'll look at a lot of the same sort of principles and see how I accomplished a lot of the same things.

  • So this is also the last lecture of the semester, and we've covered a lot of ground.

  • Have a few screenshots here to show some of the games that we've talked about.

  • You know, the very first game was Pong, and we've come sort of a long way.

  • We've gone through a very simple sort of Arcadia Tory like games like this, and you have gone and created worlds effectively.

  • And, you know, now we're in three D.

  • We're doing all kinds of awesome stuff, but these this was where we started the course.

  • Um and it's kind of fun to look back and see where we've come.

  • So, you know, here we talked about scoring and just effectively drawing shapes under the screen.

  • Then we transition to Flappy Bird or 50 Bird.

  • And, you know, we had sprites and characters, and we talked about scrolling and infinite level procedural generation type algorithms.

  • And that was fun.

  • Um, we took things a step higher than that with Breakout, where we had the same sort of procedural ideas in the context of a very famous arcade game.

  • We talked about particle systems and some arcade style physics and high scores.

  • Then we went into puzzle game.

  • He talked about match three and how to actually calculate what goes on to determine whether we've got a match and how to clear blocks and had between things do operations overtimes or this a synchronicity.

  • Um, Then we went into probably what is my favorite lecture, which was Super Mario brothers.

  • And we talked about how to create procedural worlds that all look very different with some very simple algorithms.

  • And then we had triggers and events sort of happening.

  • The legend of Zelda came, and we had this infinite dungeon algorithm, and we had enemies walking around that we could use a sword on.

  • So it felt more like an actual action game action.

  • RPG um, Then we took a look.

  • A brief look at physics in the context of box to D with angry birds, and I still remember the like Ball pit example was probably my favorite part of that.

  • And then probably the most complicated example of the semester was Pokemon, where we actually had a full a semi full turn based battle system and random encounters.

  • And like a little world where there's actually two main stages to our world, where there was the field and the battle scene, which is a very common thing to have in RPGs.

  • Following pole came on which was the most complicated code base.

  • We went into unity, which was our first foray into three D.

  • And even though we were just exploring 2.5 d, we still got a chance to look at, You know, how does the unity engine work and how do we get actual three models onto the screen?

  • And we put together a very simple flappy bird asking game so that we could sort of recycle prior ideas.

  • Last week we looked at Dread 50 which was sort of a dread holes horror inspired game.

  • We've got to look at lighting and how to actually transition between scenes and use some basic you I in unity.

  • And today we'll be talking about how do you howto create a game similar to this?

  • Although much simpler today is mostly just a tech demo more than anything else.

  • But this is a screenshot of the actual game portal, and as you can see, they do a lot of really cool, fancy things.

  • They have, ah, portal on sort of a slope.

  • They have another portal coming out of the front wall or back.

  • They're different colors, so you can differentiate between left and right orange and blue.

  • They have sort of object here on the side, and I believe that's to shoot cubes out, which this year is a cube, which you can then grab with your gun and then shoot it through portals and see it come in and out of portals, which is pretty cool.

  • Um, and we'll talk today about howto create sort of, ah, simple version of this and primarily just the aspect of how do I create a portal that looks out of another scene and see it updating in real time?

  • Um, and how do I tell a port and get back back and forth between the portals and carry a weapon and then shoot a ray that will actually place a portal where I want to in the game world?

  • So today, some of the topics will talk about so one holding a weapon.

  • So we've had we've used the first person control, and this is a very easy and simple thing to do.

  • But it helps illustrate what parenting is, and so we'll talk about that.

  • Ray Casting is the actual shooting out of Ray from your object Z direction forward.

  • So you have an X and A y, which are sort of the angle at which you're moving around.

  • But then you have Z, which is always if you're using vector of using of the forward vector from your character, it's gonna be forward from the Z axis wherever you're looking effectively.

  • And so that allows us to, um, we can cast a ray in that in that sense, which just means, you know, shoot a straight line and invisible straight line from that point.

  • And wherever that point intersects with an object, we could get some information about that and then do whatever work we need to do in this case, take a portal, prefab and just like fix it to the wall, basically rotated from its default position and just, like put it flat up against a wall texture.

  • Mass masking is sort of how we're going to achieve this portal effect, right, because when we when we create what's called a render texture in unity, which here is the third bullet, Orender texture just means a texture that we're rendering to with a camera.

  • So rather than have a texture, be an asset in your game in your hierarchy with something that you've made a photo shop you can actually dynamically created at runtime with the cameras.

  • What the camera is seeing immunity gives us to you for free very easily with what's called a render texture, which is just another asset type and then texture.

  • Map masking is effectively sort of kind of the same thing, a stencil ing where we can choose certain pixels of an object to delete.

  • In this case, we create a texture that's white in the center and in black around the edges in a sort of elliptical shape.

  • And what that allows us to do is tell it with a simple shader.

  • Um, don't render these pixels when you actually render the render texture just under the ones in the middle.

  • And so that's how we achieve in the lips just by effectively discarding the pixels on the outer rim.

  • Decals are is an idea in three D games where a D college is something that you have fixed the texture or some object that you fixed to a surface in this case will be using decals to act as our portal.

  • So are portals are actually gonna be decals?

  • They're just meshes with that renders texture of fixed to them.

  • And then all we need to do is just slap them onto a wall whenever we shoot it and we get a ray that intersects with wall and they will have the effect of, um, actually making it look like we're putting a portal on a wall when in reality, we're just taking a mesh in or kind of slapping it onto a wall.

  • Some other examples of details that you've probably seen in other games are, for example, bullet holes, which use the same principle.

  • Teleporting is very easy, although the F PS controller sort of complicates things a little bit.

  • So we'll talk about how we went about sort of solving it, sort of solving the problem of teleporting in a way that makes sense.

  • Um, it's usually just a simple as a change on the, you know, setting something's transforms position to another transforms position, setting the rotation to the transforms rotation.

  • Um, but the FBS controller caches its rotation data, So in order to that teleport cleanly, you sort of have to override some default behavior.

  • And lastly, we'll take a look at some new tools that unity is introduced with 2018.1 pro builder and programs which allow you to actually model geometry in the scene.

  • And this is what the assignment is going to be focused on.

  • Um, because going forward, I foresee it being a major part of sort of modern unity, development and or prototyping thehe bility.

  • To model your scene in Unity without needing 1/3 party program heavily optimizes the actual creation process and allows you to do easy what's called gray boxing, meaning create a level for like, you know, to create a level in your game engine and then prototype it.

  • Test it, make sure that it's actually game playable right off the bat.

  • That's called a great boxing.

  • But first, let's get a demo.

  • So does anybody want to come up here and play my implementation of portal?

  • It's Your James is landlocked.

  • All right, James, you're not landlocked.

  • Let's go.

  • All right, so I'm gonna go ahead and set that up.

  • And so disclaimer there's actually a bug in this a swell.

  • So I'm curious to see if you can spot what the bug is.

  • Go ahead and hit play as soon as you're ready, and then the mouse on the right will be your sort of angle of your portal.

  • So we see here I have a ah character with a portal gun created.

  • So if James if you shoot a wall with left mouse, that will create a portal, and then they have used the right mouse.

  • So that's one other bug.

  • So let's go ahead and restart the program.

  • Actually, um, so that's one bug.

  • And so, um, if we avoid stepping into a portal that's there and this this could be fixed in a couple of ways.

  • Um, so now you have.

  • Ah.

  • So Okay, so now you have two portals basically created.

  • Do you see what's wrong with the portal as it is here, both of these portals actually here?

  • Oh, actually, no.

  • I'm sorry.

  • These portals are actually completely right, but walk through them and I will show you.

  • Okay?

  • So you can see it works.

  • It works pretty well, right?

  • You can not only see your character rendering completely are moving in real time when the other texture.

  • But you can while you can jump through them or walk through them.

  • You can jump with space bar if you want and that will teleport you out the other end.

  • So you see from the perspective of the other portal.

  • But if we try shooting one of the other walls, for instance, like one of these white walls, you can see something weird happens with this particular wall.

  • Anything strike you as odd about that portal Anybody?

  • It's upside down.

  • And so if you walk through it, though, it works perfectly fine now the reason that it's upside down.

  • I spent probably like 10 15 hours trying to buy what this is.

  • It's in a state of what's called gimbal lock.

  • So this prefab right here there's three axes of rotation and three space.

  • And if you perform a rotation in some odd way, um, there are these things called Oiler angles, which are your angles of rotation about the X y and Z axis, and you can sort of think of it.

  • I think of them as sort of being able to rotate and interdependent Lee.

  • But there is a situation in which you can, for some reason, Unity's internal representation of a rotation can get messed up by manipulating these angles and so you can actually lock two axes together such that, um, rotating like, for example, in this case, it Z and why they both rotate each other.

  • And so you're unable to get in this particular case, the, um, portal to rotate about the access that lets it like, um, look like it's right side up based on the walls surface normal.

  • And so, um, had I maybe another week, it probably could have debugged it, but I had to leave it in, unfortunately, ran out of time, But, um, if you don't, the interesting thing is, if you do shoot that same wall, so try and shoot that wall the other wall with, like put both put one portal on the on the buggy wall.

  • So the right wall, it's only that wall, by the way, for some reason, So, um, that wall is of its eso noticed that now it's right side up.

  • So if you shoot both portals on the same wall, that buggy wall, they do get right side up.

  • And I, for the life of me couldn't ascertain exactly as to why I know it's gimbal lock.

  • Um, unfortunately, I was unable to debug it quite in time.

  • But every other wall including the ceiling on the floor will work if you shoot a portal up on them so you can create one up there and then you can jump through it, see how it's looking down.

  • And it will sort of put you at the top, Um, and altogether minus the weird single wall that gimbal locks the portal.

  • We have a pretty functional implementation of a very basic portal game.

  • Right, we have.

  • Ah, this model here is parented to the camera, so it's always gonna look in the exact same direction is the camera.

  • We shoot a ray from the tip of the gun.

  • And then whenever that Ray intersects with a plane in this case into these walls, we get the information about the intersection and we flip the decal, the portal, Dickau such that it's the same angle as the wall rotation.

  • And then what happens when we actually collide with one of the portals just in code?

  • If we were to think about how to implement, like the behavior that goes on here is transferring the player and it's doing effectively setting the players transformed position to the same transform position as the portal.

  • Now, if we do the same thing on the rotation, the player ends up getting obits.

  • The FBS Controllers rotation gets a bit skewed if you mess with its X and Z rotation, the default controller.

  • So all we do for now is we just We keep those values the X and Y rotation, but we just change the Y rotation.

  • Why rotation is his position in space like this effectively, so that allows us to get When we jump out of the wall, we notice that he's, you know, sort of like flat from it.

  • But if we jump through any of the wall portal, so if you like, create a portal in the hall here and then jump through it, you'll notice that you sort of get a you know, you're sort of angled at the right.

  • Um, and the reason that it's skewed is because this one's upside down.

  • And so it flips, though it's flipping the camera that's rendering the texture, and it's looking a little bit weird.

  • But when you jump through, um, it basically keeps your X and Z but rotates.

  • Your wife is issue such that you come out looking as if you went straight through the portal rather than um, by default it has.

  • You look like a look back at the portal that you came out of, which is a bit weird, or whatever direction you were walking through it when you went through the portal.

  • Um, um, that's just defaults.

  • It's rendering a um, it's a render texture.

  • So there's a camera actually behind each of these portals, so the prefab is a mesh with the render texture and then behind it, there's a camera, and so the camera is rendering in real time what's in front of the portal, basically from behind it.

  • And so it's seeing your model from both of these portals, both cameras or seeing your model.

  • And so it shows up in the render texture on the other, on the other on the other portal.

  • So it's effectively, like looking at two video cameras instead of a portal.

  • It's It's a sort of a trick, and this is a very crude implementation of portal.

  • The actual game uses a much more sophisticated algorithm for um, and it also tracks your position with the camera so that, like based on your angle of rotation, you'll actually see something different on the on the texture there.

  • Um, but it's a lot more complicated to put some like that together.

  • I have some resource is that have included in the lecture on the assignment.

  • That'll show you actually howto do that.

  • Um, but it would take many, many more hours than I had Thio put this demo together.

  • Yeah, it's fixed.

  • So if you actually look at it from the side, you'll notice that it's like just a flat texture.

  • There's no perspective.

  • Ultimately, it's perspective.

  • And, um, there's an awesome video that I'm gonna show later in the slides by a youtuber named Brack ese, we're actually implements a, um, prospective correct shader that allows you to see and with with camera tracking of the player like both cameras, will track the position of the player as well as, um, render a texture.

  • And the result of that is because the camera's air changing their position.

  • It's sort of like changing the angle at which the scene is being rendered onto the portal mesh.

  • Um, but also the way that's being drawn is a little bit different, and so he has a really cool shade of that Does that and then valve.

  • When they present, they'll actually show how they went about doing it, which is even more complex but looks really good and is a lot more, you know, technically interesting.

  • But yeah, that's my, um, sort of implementation, bare bones implementation of what makes a portal work.

  • So and it's somewhat, somewhat fun to, like, walk through these, um, you know, walk through these portals and sort of play around with it.

  • Now, um, the reason that if you just walk into a blue portal it doesn't work is because the portals are actually stored off screen until you use them.

  • And so a way in which saw I'll open up the scene here.

  • Oh, by the way, thanks, James, for coming up to Demo.

  • I appreciate it.

  • So the portals are over here, right?

  • Both of them are right here.

  • And so what allow What that does is when you only shoot one of them.

  • The other one is still out here, so when you walk through it, you end up just teleporting outside the level.

  • And in order to not have that happen, where you really need to do is have a flag on both of them that just says Don't teleport unless they've been shot once.

  • Right?

  • And that will prevent that will prevent that sort of behavior from happening.

  • Simple fix.

  • Um, but an entertaining one to take a look at.

  • And that is my crude implementation of portal.

  • It's far from being anywhere nearest polished as the actual game.

  • Um, and there is tthe e slight weird wall that gimbal locks the portal, which I would like to figure out why exactly that is.

  • But everything else is sort of in here now.

  • It doesn't include something like shooting blocks through it, but the same sort of principles would apply because all were effectively doing on the portal is saying it is basically a trigger, right?

  • It's got a box collider on it.

  • And it says, if I collide with something in this case, the player, um, I want to teleport that collider to the other portal, which means that the portal sort of have to link to each other, right?

  • One portal has to have a reference of the other portals that it can say teleport to the linked portal, and vice versa.

  • The link portal should have a reference to the other portals I can say help or back if you Clyde with this.

  • And so if we have another object like, say, we shoot a cube into the portal, it would also get teleported to the other portal.

  • Right and other Other consideration for that is like if it's, ah, a rigid body and has physics applied to it, for example, let's say it's It's going like 10 on the X, and it teleports to a portal that's like, perpendicular to it.

  • And it's still going 10 to the X, then assumes it shoots out of the portal is gonna go straight left, which isn't the behavior we want.

  • We want it to go forward.

  • So it's like, um, linear velocity needs to be calibrated to go in a different direction.

  • Didn't have enough time to put a full demo of that together.

  • But if you're curious in a nutshell, that's sort of like what you would need to do in order to implement, like some basic physics with, uh, portal.

  • So holding a weapon based on the screen shot, can anybody tell me how they think I got?

  • I went from just a plain FBS controller to an FBS can.

  • Sure, holding a gun.

  • 11 you?

  • Yeah, there's not really a notion necessarily of pixels in three space, because that changes depending on your resolution, but, yes, unity units.

  • So it's effectively equivalent to a meter, and you can change what it represents in unity settings.

  • Um, but yeah, I mean, it's not It is.

  • It s So we have to be one unit.

  • It could be an arbitrary amount.

  • And what it really was was me going into here with this model, by the way, got this model on the asset store for free.

  • So the acid store is an awesome place If you're looking to just quickly prototype your game, they didn't have any, Like, obvious Portal Gun's portal gun lookalikes.

  • That looked really good.

  • So I was just like, all this gun's got, like, the same kind of color.

  • I'll just choose this like a sci fi kind of gun.

  • But as you can see, there's a hierarchy here.

  • Now, how are we keeping the gun like a fixed to where the camera's looking?

  • Do we know you think it's your first?

  • Yeah, They Yeah.

  • You have the camera followed the gun.

  • Do we know.

  • Do you have any guesses how we're doing that?

  • It's actually really, really simple thing.

  • Yeah, So all we're doing, Steven transformed.

  • This is for yeah, kind of so set the guns transformed to the cameras, transformed.

  • But just with an offset that is effectively what we're doing.

  • And in order to accomplish that, it's really as simple as just making it a child of that thing.

  • So this is the first person character controller.

  • It's got a camera attached to it.

  • Anything that you parent to something or you make a child of something else, it's gonna have the same transform like change is applied to it, including rotation.

  • So by making the gun just a child of the first person character, which is where the camera is here first person character, by the way, is just a sub component of the FBS controller, which every name to portal gun FBS controller Here, the portal gun.

  • Anytime this first person character is rotated, which is the camera.

  • So any time the camera is rotated, it applies that rotation to the portal gun gun.

  • Here, this gun mesh and so that gives you the effect.

  • So what you do is you started off by, you know, you figure out okay, Where is the You start off in three D space like this.

  • You're looking at your game scene and you have your character, and then you move your gun object around.

  • In this case, I could go.

  • Let's go to layouts two by three.

  • So I could see in real time.

  • So this is the game view.

  • This is what's gonna click on.

  • Start up.

  • Uh, I'm gonna go over to my game, my editor of you here, And I'm just going to grab the actual gun component here.

  • The gun object, I should say, going to position it and I just move it right.

  • And so this is how you can, like, change where your gun is relative to the camera and this is going to effect sort of how it feels, right.

  • Like I could put it here, and it's kind of a little lower.

  • I could put it here.

  • It feels a little weird, obviously, because it doesn't have a hand on it.

  • So it's kind of almost looks like a V R game.

  • That's kind of like what BR games do is they take your hand positions and then they like the gun transform is locked to the basically where your hand controllers are.

  • Um, in this case, all I did was I just positioned it.

  • I said, I like how it looks right here.

  • So I'm just going to do that.

  • And as soon as I make it a child of the first person character, which is the camera is just gonna get all the rotations applied to it.

  • So any time we make any rotations to the camera which are doing here, it stays exactly aligned with the with the camera.

  • This applies to any operation that you do in unity.

  • When you make any sort of transform position, scale changes, they all get propagated down the chain.

  • All the objects that are Children of an object that get transform operations applied to them.

  • We'll have the same transform operations applied to them, sir.

  • Like this recursive kind of effect?

  • Yeah.

  • First and then you just you're correct.

  • So if you have, if you just import the vanilla FBS controller and then just make the gun specifically, the gun needs to be a child of this, the first person character of it, Because that has the camera and recall the cameras.

  • What's driving our rotation right?

  • Because we're moving the cameras rotation with our mouths.

  • That is ultimately going to determine how the transform gets applied to the gun.

  • But yes, and so just whenever you're doing anything in unity and you'll do, a lot of things were like one thing's movement or scale or rotation should apply to another thing.

  • Just remember, that's usually just as easy as making it a child of something else.

  • So any other questions as to how we've gone about implementing the weapon?

  • All right, So Ray casting So Ray casting is a nice feature that unity gives you for free.

  • Um, it's part of the physics sort of name space immunity, part of the scripting a p I.

  • And what allows you to do is effectively look at from whatever transform your operating at or whatever opera transform you give it as a the source.

  • So whatever point you give it as the source, um, you can tell a direction given a vector as a direction in this case, what we're doing is, we're saying transformed out forward and transformed out forward just means basically wherever we're looking x and Y and then straight in the Z direction.

  • So if you're doing it on a camera, it's always gonna be exactly what you're looking at.

  • It's always gonna be exactly forward on the like.

  • Transform, not forward on a camera is always gonna be like center of the screen wherever you're looking at.

  • And so if we cast a ray from the point of our character or actually we're doing it from the point of our gun to the transformed out forward, like a line going from Mark Player to transform its, ah, the Ford vector of its character, the forward vector of our camera.

  • It's going to have the effect of, um, weaken shoot something right we can.

  • We can create a rate cast, and it's like a fix something wherever that rate intersex and will be the exact center of our camera view.

  • Does that make sense to shoot a line from the zeal your Z axis, which is your forward vector, and then based on how you've rotated the camera X and Y, are there X and y part of that disease?

  • Always forward, that'll let you shoot things or cast raise directly in front of you, and you can cast raise between any object and from any source point with any sort of direction you want.

  • But it's particularly pertinent in the context of how we've shot it from our gun.

  • And so here's a screenshot, actually, what that looks like.

  • And so the nice thing about unity actually is it has a function called debug ray or debugged outdraw Ray, which I'll show you here.

  • I implemented it in a function called D ah ah component rather called debug ray, so that you can actually see where a raise being cast in your scene and eliminate any ambiguity there So you can see draw Ray transformed opposition and then we just say, transformed out transformed direction vector three dot forward and then times 1000 just means 1000 units, you know, from that point and then colored out red.

  • And so what that will do is only in the only in the editor view, So this doesn't apply in the actual game.

  • There's just a debug, Um, call debugged, outdraw Ray.

  • And so it'll render in the this scene up here, just not down here.

  • So if we kitt play I actually have all the portals rendering a deeper grave from their forward transform.

  • And for my gun, you can see it there.

  • I'm just doing a debug dot draw array with just transformed out forward.

  • And, um, using my transformed opposition is the source point and forward is always gonna be noticed that the zero always always following the same direction, right x and y are sort of changing.

  • You know, the back planes are like how that's rotated.

  • But Z is always forward, right?

  • And so that's the That's the raid coming from our gun.

  • And if we shoot a portal there and there, I have those also set to, um deposits.

  • I can rotate the view a little bit.

  • I have those also set to draw a ray from their forward position.

  • So those air also drawing array from what's their vector three.

  • Are there transformed up forward their directional vector.

  • Um, but yeah, great casting.

  • It's pretty.

  • It's pretty easy just to get, um, some pretty simple collision test this way with guns with a lot of different things.

  • But primarily you'll see this used for, like calculating whether something is blocking something else.

  • Like if a car is moving and it's text.

  • Maybe if it detects another car like Avery and Grand Theft Auto, for example, and your car's driving down the center of the road or something, and it wants to know whether there's a car, two units in front of it or something.

  • It is cast array and see if there's any geometry there from its forward vector right transformed opposition card opposition and then get its forward vector, which will be its easy direction.

  • And then it depends on whether it may be your game's top down.

  • Maybe it's not your forward vector.

  • Maybe it's your Y vector in that case, um, but that'll effectively give you not only that, you've got a collision but also tell you where the collision is, too, Which is nice.

  • Um, we do that in the portal gun script where we call physics that Ray cast.

  • So this this is the function, by the way, to actually do the raid cast.

  • The interesting thing about recasting immunity is that it returns a struck object, and so you needed declare this hit object, which will tell you all the information about the hit, so like where it was whether there was a hit to begin with and what they're like.

  • The normal was on the surface that it collided with the angle at which that, um, sort of plane was projecting out.

  • And then you call physics that ray cast with a position and a transformed direction and then you passing out hit so out is interesting because out is sort of see Sharps way of allowing you to return multiple values to something so out is gonna be an object.

  • A In this case is gonna be our Ray cast hit that we declared up here.

  • Right, which is instruct which recall is just a collection of variables like in C or C plus plus, um, and outhit just means that normally we pass in these values to the function that they don't get manipulated, right, But we pass in this variable as out which will allow this function to actually change the data inside this this hit variable.

  • And so the result of that is hit from this point forward contains all of the information about the ray cast that we that we that we just triggered, and when we call methe f dot infinity That just means, um, Ray cast to infinity, which, until you know forever, never immunity obviously doesn't check infinitely whether something's collided with something, it optimizes the right way.

  • But you can use that.

  • Just if you don't want us necessarily specify.

  • I want to check two units or five units or 1000 years in front of me.

  • I want to just check forever and see if it collides with something and you're seeing right.

  • Um And then, as you can see here once that once we have detected a collision, we play a portal sound.

  • We get the right portal and then we set the portals transform and rotation based upon the hits point and rotation.

  • And that's pretty much all that's involved in shooting the gun.

  • And you can take a look through here if you want to get a sense of how it works and maybe explore also the ray cast the physics that Ray cast section of the a p I just to understand what exactly it returns and what you can do with it.

  • But in this case, this is how we're using it to detect whether we've intersected with wall so it will intersect with any sort of mesh, and when it does, it'll tell you exactly how it did.

  • So that is what Ray casting is.

  • Ray Casting has another name for, like old school games like Wolfenstein.

  • The method of rendering was called Ray Casting, where you generate one sort of, uh, you would generate a ray from every pixel of the screen effectively, although it was mostly just every line of the screen, and you would just look up and down for everywhere, intersected in the scene and then just create draw like a texture there, and so that would generate a world that would that looked three D.

  • But you couldn't move up and down because it was always generating all raise completely forward, and so you were locked onto two axes.

  • But Ray casting is different immunity.

  • Recasting is just literally casting a rate in 30 space versus the sort of to D space that it was casting.

  • In games like Wolfenstein, there's another screen shot of ah, normals from our portals casting out rays, and I want to look up and see if I can just find a picture of what Wolfenstein looked like.

  • Um, I'm pretty sure most folks are probably familiar with not the new one.

  • Yeah, Wolfenstein three D.

  • So this was this is Wolfenstein So old school.

  • But this sort of ray casting was different.

  • It would go over.

  • It would basically shoot rays from every single line of the screen up and down, and it would detect based on the level geometry, which was very simple level geometry.

  • It was just basically whether there was a wall.

  • There are not true or false, Kind of like a to d image.

  • Um, and it would draw based on how far away it was, that particular point of the geometry.

  • It would just draw like pixels from a texture, a specific texture.

  • At a specific point on, they had to interpret late where on the texture, it was more complicated.

  • But in case you see Wolf in Star, in case you see Ray casting used in those two different senses in the case of old school, um, game engines, in the case of, um, uh, modern unity sort of recasting, that is what is involved in that.

  • So any questions as to how sort of in a nutshell the rate casting works in the context of our game here.

  • So, uh, unfortunately, no, the Oculus does not work on Mac.

  • They didn't have Mac support.

  • And so, uh, we were unable to get a sort of version of it working.

  • We don't have the means to necessarily transport.

  • Um, given how much time we have now, getting V are working in unity is actually very easy.

  • Um, fire call correctly after.

  • Just remember the exact menu I had sort of anticipated talking about this before.

  • I think it's player X r settings.

  • Yeah, that's what that's what it is.

  • So in order to get those incredibly easy, if you want to do a game, envy our immunity and you have a PC out of the box.

  • It's very easy just to get it working.

  • All you need to go do is go to edit project settings and then go to player and then in the X are setting.

  • So Unity has, like, deemed all of its V r A r stuff as X are, um and you click Virtual reality supported here, and you have your Oculus rift or revive or whatever plugged in.

  • It'll just work with the camera, like crap right out the gate, so it's pretty easy.

  • You may have to insult drivers on your computer such that your computer knows that you have innocuous plugged in.

  • But assuming that's all set up, your project Wu is as easy as just clicking this check box.

  • Um um, hollow lens, um, Oculus rift.

  • And I'm pretty sure the violent 90% sure survive.

  • Um, I'm not 100% weaken.

  • Weaken Google it.

  • Let's see unity what more it looks like it does.

  • It looks like it definitely does.

  • Yeah.

  • And of course, if he already Windows PC is very I apologize.

  • I thought I totally thought going into the course that unity.

  • We're, uh, that Oculus worked on a Mac.

  • Um, but as of even October, they were like, it's not gonna work on any Mac book ever released.

  • So only on a PC.

  • Unfortunately, um, that said, if you do have a PC super easy to get working, and it looks like this is actually pretty cool tutorial.

  • I haven't looked at this, but, um, I tend to like Ray, I I don't know if his name is vendor leash or Wendell itch, but he makes really good to game programming.

  • tutorials in general.

  • So just, you know, because we're coincidently here.

  • If you guys are curious, I really like this website for basic tutorial stuff we have I've, um, and VIAS Faras I Well, five.

  • The thing about vibes you need to install.

  • Like what?

  • Like ceiling mounted cameras in order for it to work.

  • So that's kind of out of the equation.

  • We have the gear v r, but you would need it.

  • We would need to export it to mobile and test it and just didn't have I didn't anticipate it not working for Mac.

  • And so it kind of came up a bit late, and so it's on me.

  • I apologize.

  • But if you are doing a PC game innocuous and you want some assistance, I'm happy toe like help out.

  • It looks like it's very easy just to get working with the default FBS controller camera.

  • So, um, definitely reach out if you're developing Oculus and need some assistance, Um, maybe for the next iteration of our next unity course, we can have Ah, a big sort of V R day or we bring in all the guns.

  • Um, but yeah, back to sort of re casting, and we were just talking about, um, shooting array on your Z axis based on your rotation.

  • Get information from it, and then sort of what we do is we flipped the portal based on the hit dot rotation of the surface that we collided with.

  • And that's effectively all the rate casting that we need to worry about for portal.

  • Um, but the actual making a portal is probably the most interesting part of this whole project.

  • And so let's go ahead and go back into present mode.

  • So a render texture is the means is a very is a basic is not a basic means.

  • It is the fundamental way which we go about doing it.

  • And there are various ways to accomplish doing it, some that are more technically challenging and look a lot nicer than others.

  • I did a sort of simple version of it just to get a sort of proof of concept out of the gate.

  • But unity makes it really easy just to get a simple render texture up and running.

  • So Orender texture is recall just a texture immunity.

  • So it's an asset.

  • It's immunity asset that you can create the difference between a render texture and a texture that you might have imported from like photo shopper gimp is that a render texture can be rendered to, and typically this is used for things like cameras being rented to it, although from what I understand, you can render anything to it so you can create procedural textures this way as well.

  • But in this example, here we're creating a.

  • We're essentially creating a screen into which we're looking at the viewpoint of our other portal, right from from its four direction.

  • So we can see what what it will look like once they walk out of the portal and go into the next area and so a render texture.

  • So I have some in the slides.

  • If you want to download the slides they're here.

  • You can see exactly how to create a render texture so literally just create and then render texture that creates you're under texture.

  • These the settings that I used, um, for the actual render texture.

  • So what'll happen?

  • Do we think if we use, like a low rez, render texture just logically and say What if my render texture was like 200 pixels?

  • My tumor pixels, and our resolution of our game is like 10 a teepee just like you.

  • It won't be blown up because what we're doing is we're taking a mesh, and we're fixing the texture to it.

  • It'll just scale to fill the mash.

  • But what will it look like when it's rendered?

  • Because it's rendering a 200 pixel texture, it'll pixelated.

  • It'll look really like nasty.

  • And so, in order to fix that problem, typically, what you'll do, a smart way to do it would be to dynamically figure out at runtime what's what's the resolution of your game, right?

  • If it's gonna be rendered in various resolutions upto four K, maybe down to 7 20 p um, and then create a render texture that is the size of your game.

  • And then, by doing that, it will ensure that no matter what your resolution is, it will always be 1 to 1 pixel ratio.

  • Even if you're right up close to it, right, it'll fill up your whole screen.

  • Um, in this case, we went for a simpler methods, so we didn't have to do any dynamic in Stan she ation of the render texture, which you can absolutely do, and it is the more robust way to do it.

  • But in this case, I just chose 10 24 by 10.

  • 24 figuring that that was gonna be good enough for demonstration purposes and most of these other settings, I believe, actually, all these other settings are completely default.

  • Render texture settings.

  • The only ones that changed where this is 2 56 by 2 56 by default and just looks really pixelated and nasty.

  • Especially when you're right up close to it.

  • Um, and then all we need to d'oh.

  • So once we've created a render texture right in our in our scene in our assets, So here I'm gonna go to textures.

  • This is where I'm storing all my textures, whether they're render textures or not.

  • I have these to render textures here, and so these are by default.

  • They're not gonna be mapped anything because they're just There's empty rendered textures were affected.

  • The allocated them and said something will be rendering to these later.

  • But for now, they're just empty.

  • There's placeholders right there, like blank screens.

  • But they had TV hasn't been turned on yet in order to actually render to them.

  • We go into our first person care or, um, sorry, not a first person character.

  • We go into whatever camera we want to render it, to render to the render texture because we're effectively taking these render textures and we're rendering a camera view onto them, right?

  • Each of the portals has a camera behind it, looking out from it.

  • And so we want to take that camera's of you, and we want to render that onto the other portals face.

  • The other portals render texture the texture that we're gonna put on to it.

  • And so all we need to do, it's say, here is my orange portal.

  • I have my camera here.

  • Every camera has a target texture just right out the gate so you can just say, Okay, take my orange portal texture, my render texture that have been Stan She hated.

  • So it knows that it's gonna be able to receive an input source, and I'm going to just click and drag it there, and it's that simple.

  • Now, whenever you run the game, you'll notice that your render texture updates.

  • I'm not sure if updates in real time and inspector, but it renders if you're if you're showing it onto a yeah, doesn't render in the inspector, but it will update if you have fixed it to any other surface.

  • And so what we're doing is we're fixing it to the meshes that are associated with each portal.

  • James, did you have a question?

  • Oh, sure.

  • The render texture.

  • So just right.

  • Click.

  • And then I go to create and then a render texture right here, and that will give you most of the settings that you need to get up and running with it, and you can assign it to a camera.

  • But the important thing is, do you consider your resolution for re render texture?

  • Make sure that's high enough, such that your game won't look pixelated when you're looking at it like pretty close up.

  • You see that?

  • Yep, yep.

  • And so that will do is create a link between the two.

  • Such that anything the camera sees, it's no longer going to be rendering to the scene or anything like that is gonna render to the texture.

  • And actually, I think you can run into the scene and the texture, but these aren't rendering, um to the scene at all.

  • They're the only one running to the scene.

  • Is the first person character because it's the default camera main camera.

  • It's part yeah, um, if it's a high, too high of a resolution is just going to, like, compressed to fit the mesh, Whatever.

  • It's a fixed, too, and you'll probably run into performance problems.

  • But it's not gonna break.

  • Yeah, because you're not fixing it to any cause your resolution.

  • It doesn't really have an effect necessarily on whatever's in your game world and like that doesn't cause any issues.

  • Um, it gets it gets interpolated like unity will just, like, calculate how to render it to the screen, right?

  • Yeah.

  • Um, like game textures generally are very high resolution, like, 4000 by 24 K.

  • Textures are often used, even if you're running your game in 10.

  • 80 p.

  • And a game engine will probably optimize it and, like down sample the texture so that is like actually attended tp texture.

  • And you don't like you're not trying to calculate more draw more than you need to.

  • Um, but unity will figure that out for you Don't have to worry about that.

  • Um, but yeah, that's that's what a render texture is.

  • And that's that's how we are creating this illusion.

  • Remember, everything in the game is an illusion.

  • Um, in this case, we're not, actually.

  • And it's it's obvious in this example, because we're not, actually because the Texas air flat and there's no perspective correction.

  • You can see that it's a texture, even if it is slightly convincing from far away, like from far away.

  • It actually kind of looks.

  • I mean, I don't know if it necessarily looks real.

  • Um, I mean, it kind of does, right?

  • Like you from here.

  • It's hard to tell, and from here it kind of looks like we're going into another room, right like that.

  • That's the broken wall.

  • They go like that, right?

  • There's a portal there, and it kind of looks like it's a really room that we're walking into.

  • It just a resolution.

  • But all we're doing is we're just drawing a camera's view onto that texture in real time.

  • And if you notice you can see our gun, that's kinda hard to see.

  • Actually, um, what's he going to it from?

  • There may be, Yeah, there we see a little bit better there.

  • When we move, we can see the gun.

  • So it's We can see this rendering in real time, and that's the power of a render texture.

  • And this allow you to do all kinds of things you can have, like, uh, TV screens in your game that are rendering another part of your scene.

  • Um, obviously an example like this.

  • We have a portal looking into another area.

  • Now, if you apply a perspective correction to this, whereby your camera actually tracks where your players position is related to the portal, you can accomplish a much more believable look.

  • And you can actually make it seem as if you're looking into another area because the camera is literally moving with your player.

  • So the cameras, like the stuff that's capturing is gonna be changing a real time.

  • Not only just your character's model, right, actual angle is gonna change and therefore be perspective.

  • Correct.

  • Um, and there's a awesome tutorial I'm gonna link to in the slides that'll show you how to go about doing that.

  • It's really awesome.

  • And so this is what it ends up looking like.

  • This is actually before I changed one of the portals had a slightly offset camera angle.

  • So you can see here.

  • This is like a little bit higher than this one is.

  • They should be exactly the same.

  • But it's fixed now, so so texture, masking off any questions about any of that process before we talk about texture masking.

  • Okay, so texture masking is basically the process.

  • So here's a If we just take a plane and we put a render texture onto it, that's what it looks like.

  • It just looks like it's just square.

  • And this could work fine.

  • If you want a sort of a square portal, look, you have to do any extra work.

  • But if you want a circle right, you can't really create like a circle shaped plain object that doesn't really exist.

  • And even even it did, it wouldn't be efficient, especially if you want a very smooth, um, plane, because everything is triangles and polygons, right?

  • So if you're if you have a circle, it's gonna be a bunch of these through fanned out polygon, especially very high rez circle like one of these.

  • That's a very high rest circle, making a polygon that looks like that is not It's not an optimal way to go about solving that problem, right?

  • And much more optimal way to go about solving that problem would be to say, to designate certain pixels of of some texture as being pixels, that we want Thio read and then certain other pixels being not pixels that we want to read and therefore producer the final image that gets put onto a geometry.

  • Right?

  • Um and so what we end up doing is creating an image first.

  • So it's this image, which is kind of hard to see, but it's just a simple sort of music I see from Megan.

  • So it's just a simple oval writes the exact shape that we want a portal to look like.

  • Um, and the pixels that are white are the pixels that we're gonna render, and

All right.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

ポータルクローンチュートリアル in Unity - CS50のゲーム開発入門 (Portal Clone Tutorial in Unity - CS50's Intro to Game Development)

  • 1 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語