Title: Creating an In-Game Cutscene for Unity Free / Pro
Platform: Unity Tutorial
In this tutorial I show you the basics of disabling certain parts of the FPS controller, changing cameras and focusing on a specific scene. Whilst showing you how to switch between scripts and functions and then giving control back to the player and main camera! All about creating an ingame style cutscene!
Adding explosive force, Unity Doc: http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddExplosionForce.html
Keep yourself upto date by finding out about new and upcoming tutorials on: http://bigrookgames.com
hey guys so I’m gonna show you in this unity tutorial how to make an in-game cutscenes today and this can be used in unity per unit free whatever you want to use because the problem is that the unity for you can’t use movie textures so you can play a video if you wanted to make it is your little cutscene so you’ve got to incorporate things that make it real time and again so i’m going to show you a really basic where that’s gonna let you have a new camera do something with this camera disable all your first person troller elements and actually do something then when the camera looks an object and then switch control back to player so then you can actually play the game again so in my seen all of God is much my physics objects I’ve got ten vaults boxes each with a rigidbody component if you got a component physics rigid body and that just means they’ll be affected by physics and the ball got use gravity ticked and i just got a basic seen with a quick texter upon got sort this out of the time i’m a first-person controller with the main camera and then a second camera which is positioned in the back corner of the room and you can make one of them is you go game object Crale there and then camera and what you can do is if you if you wanted this view you can click a line two view and you can line it to whatever view you’re looking at in your actual seam deal but when you play the scene and you’ll notice that you know you’ll have camera two is the main camera and then you’ll be able to play around with the character controller now in a cutscene you don’t want to be able to use that first control that you don’t want to be able to see it and you want to make sure this camera two is the one that’s going to do something and then i’ll switch control boxee can play is it so we’ll start rolling and I’ll start off with something something basic this is going to be is going to be part of the cutscene so i’m going to create as i’m going to career a script called box physics and mom going to do here is this box physics is gonna watch should be one will do for my cutscene so let’s remember boxes explode so I’ll do run through this quickly because you can find this on the unit script in reference about an explosion too rigid bodies but for the sake of this we don’t need to cover it too much if you want me to cover it i will do and we can show how to make things explode really quickly now we don’t need to have this yet because that’s referencing couple of bits that i’m going to show you later on so regular i’ll put a link in the description of how to get the script and all it does is has a radius of power and you’ll notice that if i get rid of this is well this is what the script looks like you’re twisting it just takes all the colliders in a certain range and certain radius and eggs and explosive power to them and that’s all it does and then it just makes my blog so i’ll save this and it’s my box physics script and that’s basically what we want for now so that’s going to make the box is blocked watch what I’ll actually show you what happens so if i click on cue born at box physics what I’ll do is set the read you something like a hundred and set that’s 10,000 or something ridiculous when i apply this to unbox it won’t do anything because accept myself is on its own function so what we’re gonna do it is i just said to have a function start so soon as the script loads or their work will play the scene and you’re not just the blog soon as the actual scene starts so there’s just the basic script that right so we’re going to create another script and this is going to control what our men comes to how we disable some scripts and the basic stuff we’re going to create for cutting so i’m going to call this camera switch and keep these named as I’ve known them just so you can follow along because you’re going to need to reference them the script so if you notice now we’ve got will delete these two out will say when it’s set to variable so we’ll say camera one and we’ll set that as type camera and what’s create another variable camera to and set that is type camera and then what I’m going to do is create private variable called box physics can spell physics right and then set that to type box physics but to make this differentiate from the actual and variable name will just about a lowercase and then we’re going to write is gonna write function start now we’re going to curly brackets and what we’re going to say is that game object with two capitals . find and then we’re going to find the first some controller as its spell in unity so if we go back into unity and you see the first person control you’ll see it there with the spaces in and then we’ll said . getcomponent in brackets FPS input controller . enabled equals false so we save that what that means is that the star will find the game object called first-person control and I’ll find something called input FPS input control and that’s what let’s use year and keys to actually control so if that’s as false you won’t be able to control it and you won’t be able to do anything then what we want to do is copy this Sam line or pass 10 and then what want to do is find game object called graphics and in unity the graphics is this and it’s the capture Clyde all whatever using this year umesh and we don’t want to show so we’re going to get rid of the mesh renderer so we’re going to say get compare on and mesh renderer that enabled equals false and then we’re going to actually reference are two cameras so camera one . camera not enabled equals also whatever he says the main camera or whatever we set the camera one will actually be disabled and camera too . camera . enabled equals true so whatever putting that variable slot that will be enabled and for now that will be ok that’s what we’ll do is we’ll go on the main camera on what pop camera switch on that we’ve got two spaces report man come on come forward and that on camera too you’re not on a plane again you have my boxes explored run camera dealers will be far but you’ll notice that we don’t have the FPS controller in the scene anymore so you’ll notice that if I gone the first person troller the FPS employees been rid off the graphics the mesh renderer is gone and then have changed our controller as well so if we gotta play so that’s that’s nice as it is now what we want to do is actually do something with the camera too so actually works that cutscene salgo window will go animation or more say that work on your animation by clicking up and then what Clay all named mrs. camera zoom to do is click on transform so selects all of them add a keyframe at the top go across to about a second and i’ll do is then grab my camera make it go to watch my boxes ok so I can see in the love you and then we could scrub back and not just flies towards my boxes not so careful now so that animation is now on camera too we want to take place automatically we don’t want to play automatically will go back into our cameras trips can switch script and then we’ll say camera too . animation . player and then we’ll put closet brackets and pop semicolon and then what we’re doing is making that actual animation player when we start so I ever do without you’ll notice that my camera zooms in and then explodes but we’re going we’re going to sort this out so what we need to do is actually reference the f the function here so i change this function back to explode so we’re going to want to make this act only when we actually zoom den unweighted period of time so as I added a private variable prepare for boxes x we’re going to say at the bottom are going to set box physics equals game object . find and we added it to Q born and then we’ll say getcomponent then we’ll open a bracket and say to capital box physics so box physics is the variable here then the script is actual box physics so we’re setting it to that will find in this and then what we’ll do is then after we’ve done the at the camera animation will say yield we’re four seconds and then what part 2 2nd something like that so we’re going to wait to second then we’re going to call new function called move boxes and under here going to say function move boxes then we add our two curly brackets and say box physics . explored so what we’re doing is we just call in the other function in the script so I’ll mean in our the script or go to our the script will see in here will see that when explored is called it will do the explosion and what we’re in touch do is give the control back to the script when we’ve done so what I want to do is I’m going to create another function called go back because it has a problem when you call back to function when you’ve written a yield doesn’t like it salt will do is we create a new function here so when we get to hear just run to this function and say say yield where four seconds I’ll explain all this at the end so it makes sense when wait three seconds and we’ll say what would say so we need to add a new variable also private variable camera script or set this to camera camera switch groups cover switch because it like we did here this box is accepted box physics and we ask it to find the component we’re doing in this script now so we can go backwards and then we’ll say when explored is called boasts a camera script equals game object like before . find and then we’ll find men camera so it’s attached the main camera . getcomponent camera switch like here close that i would say will find that component so when we go to go back to this function that goes back to our camera scriptable said i will say is camera script . and what we’ll do is call this men camera switch because we’re gonna actually go to a function in our of the script so if we go here and then what we’ll do is we’ll make another function will call it men camera switch lab the curly brackets and then what we’ll do is we’ll copy these two lines as the men set this one to true and this one to false and then we’ll say was well-liked find these again also first-person trouble set up to true then we’ll set this to true we’ll save that out never go back into unity and I gotta narrow so you make sure that you remember that the variable needs a semicolon at the end sometimes forget what will happen is we’ll play the scene so zoomed in towards it where is a few seconds things fall where it’s a few seconds more and then we give control back to players so you can play as you would befall so that may have been quite confused and quite daunting but i’ll go through again so railing all we’ve got is we’ve got the boxes in the same we’ve got one of the boxes and it’s named you bored we’ve got box physics quiz attached to that we’ve got one man camera and we’ve got cameras which attached to that so if i go back into cameras which will not to start with two variables come on camera too says camera all were doing is on the start will find in the components that we need so we find on the first person troller the FPS the FPS input control we disable it we find the graphic scale object and we disable a mesh render we’ve added the main camera one camera two we set main camera at first false and then the second camera the true so we can play that we play its animation that we made and then we’ll wait an amount of seconds so we’re two seconds after it’s done now and then we call the function move boxes and what move boxes does is that it goes to the variable that we set which was box physics or box physics is this script and we call the function which is explored and there is explored and when we go to explored you’ll see you’ll see that were actually doing the script which makes the boxes blow up and we call function go back and go back we made here and we wait three seconds before that the camera script that we set up here and is called as cameras and switch and we found that by finding the main camera component getting that component we wanted more calling the function again which is in over the script down here and so after waiting three seconds it goes to this function it gives and the main camera true so enables again it’s turns over the camera off and actually gives us control of the player by Senate true and turn in the graphics back on so we can actually see the play if we need to so realistically basically as i said before the camera zooms in as soon as it plays where two seconds the cube blower goes back to our function and now we have control back of the player so you had to cut scene whatever you wanted so natural fact in your box physics said that this was so you call this exploit you could do anything here you can do anything you wanted you could start another animation plane you could create an explosion he could create a zoom in on the characters first anything anything you want anything you need to do this is just a basic of the men points are actually disabled and they’re facing but controller the graphics and choosing what can we want to use and then doing it like that and if you need any more help on this subject please let me know and i’ll try and you know make it more of an easy option but give it a go and tell me what you think so that’s pretty much it cheers and if you liked the tutorial don’t forget to Like comment and subscribe