How To Make A Spline-Based Side-Scroller Camera In Unreal Engine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another Unreal Engine 4 and 5 tutorial so in today's video it's gonna be a nice quick and simple one where we're going to be creating a spline based camera system mainly for a side-scroller game so let me just hit play and show you what we're going to make today so you can see we have our camera looking at the player like so as I go forwards the cameras can go forwards and as I go back it's going to go back as well so the camera is going to be following the player and where we go however this isn't attached to the player blueprint so it doesn't actually matter where the player goes it's just purely based on a spline so you can see this spline here this is where the camera is going to go so for example if I were to just move this piece all the way up here it's going to look terrible but you can see that it is following the spline not following the player so you can see it's kind of gone up there like that it didn't go up as high that is just purely because of there's not a lot of points in between so if I were to just keep adding in loads of different points in here like so it would do it because that's how it's working it's not just following the white line it's following the different points as well so again this is going to look very very janky but just to get the point across of how this is working is going to kind of go up and then it's going to snap between them but you can see it's on the left up there and it kind of snaps down again because I haven't got any on the right there but you can see how that's working it's going from these points all the way here like so so the more points you have the more smoother camera is going to be but it's very very easy and simple to set up to go where you want to have a custom camera track as you can see here so you can go where you want in a level without specifically having to follow the player so this is what we're going over and creating today so without further Ado let me do this code and I'll show you how I've done it so the first thing we're going to want to do is we want to actually create this camera spline blueprint so I'm going to hit control space to open our content browser right click go to blueprint class we're going to create an actor I'm going to simply just name this BP underscore camera spline and I'll open this up straight away in here all I'm going to do is add in a spline not a spline mesh just a spline we'll compile save that and that's all we need to do in here we're not doing anything else we just want a spline that we can put in our level and we just want to do it in a blueprint so it's nice and easy so we can close that right away now we're going to open up our character blueprint so for me that's third person blueprints BP third person character but you can do this in third first or whatever you've named it now in here I'm going to hold down P left click to get event begin play or you can just right click and search for it and immediately out of this what we're going to do is get actor of class the actor class is going to be the one we just created so BP underscore camera spline or if I could actually do that properly there we go BP camera spline then we're going to right click the return value and promote it to a variable naming this camera spline or camera spline reference and we'll compile and save that so we're just getting a reference to the camera spline that we have in the level and because we're only going to have one we can just do get actor of class here then underneath this we want to actually do the code to move the camera to the camera spline so I'm also going to be doing this in a nice smooth efficient way which will give us a nice smooth camera movement look which you typically see in a side Squad of games so let's right click and get event tick now we are doing this on tick but don't worry it is perfectly fine as we're not doing a lot and you can still use eventic if you need to then we're going to drag out and get the follow camera out of the follow camera we're going to set World location connecting that into the event tick there so we're setting the location of our camera in the world like so but what do we want to set it to well we want to set it to the location on the spline so we'll get a reference to our camera spline reference here out of this we're going to get the spline so that should be at the bottom here just get spline and then out of this we're going to find location closest to World location and the world location is going to be get actor location so just the player's current location so basically the closest point of the spline to the player is where we want the camera to be and we want the coordinate space to be world not local we want it to be world then we're going to get another reference to our camera up here drag out this and get World location out of the world location of this we're going to get a v interp two the target being a return value from the find location closest to what location because what this is going to do is it's going to smoothly move from the camera's current location to the location of the spline closest to the player so I hope that will make sense the Delta time is going to be get World Delta seconds and that's just the time in between each frame just so it's going to be nice and smooth and always perfect for the frame rates and the interrupt speed is how fast it's going to be I'm going to set this to two but you can set this to whatever speed that you like you can really just change this about mess with it to get the perfect values for you and then the return value of that will go into the new location of the set World location like so and this is now going to allow us to move our camera based upon the spline's position so I'll select this and I'll hit C to comment it naming this move camera and that's all the code we need to do we'll compile and save this now if we go to the viewport we just need to change some little settings on the camera so it's going to work perfectly for us so if we select the camera boom what we can do is untick all of the camera settings here so use Pawn control rotation inherit pitch your enroll we just want to untick all those as we don't want the player to be controlling where the camera goes we don't want the player to move the camera it's just purely based upon a spline closest to the player's position and then we're going to select the follow camera and we want to set the location from relative to world so we'll compile and save that so that is now absolute location instead so let's go into our level here and what we're going to do is just drag in our camera spline here and then we can simply just rotate this and move it to be where we want so I want it to start here then if I select the next spline point I can move this out and hold down alt and left click to get another spline Point here I'm going to just keep moving this out and putting them where I want them to be so where I want my camera to go is where I'm going to be placing these so again you can go wherever you want I'm just going to make it go a little bit funky just to show that this is working so again this probably isn't going to look amazing but you can just set this to be however you want just so that it is going to be working again mine is just going to be like this just to showcase the camera is following where the spline is going so we can just do something along these lines and again the more points you have the smoother the movement is going to be so that's why I'm doing this many points as you can see here so once you've got all of those in for where you want you can see this what I might do is just move the whole thing over if I select the root of it there we go I might just move this further back here and if you want it as well you can click on these individual points and then you have this line appear if you click on one of these and you move this you're kind of changing the angle of this as well so again you can make it look even smoother so let's just hit play and test this out so you can see we're quite low to the ground which I don't really want actually so I'm going to do is just move this up and then we hit play again we're now on that spline point this is the kind of height I want and if we can move this over again we can see that this is now going to be following where my spline has gone so it didn't do all that funky stuff there I think that's probably just because of how far away I am from the player it's kind of just connecting straight to the next one which is kind of good because then it shows that you can then just make it not the smoothest thing and it will still work for what you want it will still be smooth but let's say we get a little bit closer I imagine this might do a bit more of those funky movements that I've just set up there as you can see there it's kind of jumping between them so again really just set it up for how you want and we're going to get this nice smooth spline movement so the camera is following where the spline has gone so we can set this up to be where we want so for example if you were to have like an object here and you want the camera to go behind it if this was just set up on the player it would normally go in front of it but we can have this go wherever you want so we can have it go behind some object around a corner up down where the player still going straight forwards with the player still going straight so for example here I'll have it go up a little bit as you can see it went up and it goes down whereas the player isn't going up and down at all but again you get the gist I'm kind of rambling on at this point but this allows you to just create a nice spline based camera system and if I had to move my mouse the camera isn't moving as that's not how it is set up you can still obviously move the player in weird ways like this because I haven't got it set up for proper side scrolling movements but we have got the camera system set up instead though so I think that'll be it for this video as we've done everything we want to do what we've done is created this nice spline based camera system in which you can control where the camera is going to go based upon this spline here as you can see perfectly like so so I can just control that and it's going to go up a little bit and back down and then up here so thanks so much for watching this video I hope you enjoyed it and hope you found it helpful and if you did please do make sure to like And subscribe down below so thanks so much for watching and I'll see you in the next one okay [Music] oh
Info
Channel: Matt Aspland
Views: 19,119
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, blender, unity, games design, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, side, scroller, side scroller, side-scroller, spline, based, spline-based, spline based, system, camera system, camera, spline camera, follow, player
Id: ZmIzHtglnMM
Channel Id: undefined
Length: 9min 13sec (553 seconds)
Published: Sun May 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.