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?