How to create variable zoom (staged zoom in) Unreal Engine UE4 & UE5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello youtube and welcome back to another 3d ross tutorial in this tutorial i'll show you how you can create a zoom function in unreal engine and use increment stages as shown here so we can zoom in three different levels one two three and then zoom back out and as you can see we've got a smooth transition on all of them so let's jump right in and i'll show you how it's done to start off with i'm going to open our player character in this example i'm using the first person character so we neither select the character in game in the scene and go edit blueprint open blueprint or it can be found in this path here with this open i'm just going to find an empty space to start working i'm just going to start working below this code here which is the basic code we set up for the crouch function that you can find on my youtube channel but anyway back to this video so to initiate the zoom i'm going to use the right mouse button you can use whatever key you'd like but i'm just going to right click in our graph and type in right mouse button [Music] and now we've got these options unpressed so when we want when we press right mouse button we want to zoom in and to zoom in i'm going to use a timeline so i'm going to right click and type in timeline enter and create a timeline and i'm just going to call this zoom with the timeline here i'm sure double click it to open it up and i'm going to add a float track a float track is basically just a track like this and it uses a float variable instead of say a vector or a color track and this first float track we're going to have different floor tracks for the different levels of zoom so this is going to be our zoom level one so i'm just going to zoom one i'm going to set the length to 0.2 seconds and now if i shift left click i can create a point on the graph this is our first keyframe i'm going to make this keyframe start at zero and i'm going to set the value to our first person camera field of view so by default this is 90 but to double check you could click on the camera and if you open up in the viewport you can see our field of view is 90. now going back to the timeline i'm just going to type 90 in our value now with that 90 value we want to create our next value so i'm just going to shift left click again and on the time i'm going to choose the end of our graph which is 0.2 and i'm going to set our value to our new field of view so we want a less field of view to zoom in ball so i'm going to set this to let's say 75 degrees and as you can see if we type the correct file using it again because i've just accidentally moved it so if we use the right mouse button and the scroll wheel zoom out you can see there's our keyframes on the graph here now we're going to do some more tracks so i'm going to do two or three more tracks so i'm just going to add another float track and call this zoom o2 and the exact same again i'm going to shift left click set the time to zero and this time our value is going to be the end value of this track because we're going to go in increments from this track to the next track to the next track so our last value was 75 so i'm just going to type 75 as the value so this one now starts off where this one left off now if i shift left click again set the time to 0.2 and now this is our next stage of the zoom so i'm just going to use 60 as our next field of view and i'm going to add another graph and this could be our final zoom level shift left click set the time to zero and then set the value to the same as our final value in the track beforehand in this case it was 60 and then again shift left click set the time to 0.2 and set the value to our new zoom level i'm going to choose 45 as our furthest zoom so now we've got that we can zoom into 45 so i will show you this in practice in a moment but i'm just going to go ahead and create the final graph so i'm just going to rename this first to zoom all three i'm going to create our final graph i'm going to call it zoom zoom back out and again shift left click type 0 the value of our last graph which was 45 and then shift left click 0.2 and then our final value here i'm going to loop it all the way back around to this first graph so i can loop it back to our default value of 90. so we move our way through the graph this graph this graph this graph and then once we've got to our highest zoom level i'm just going to zoom back out to 90. so i'm going to type in value of 90. that way at the end we go from 45 back to 90. so if i go back to my event graph on press play we are going to play the timeline so on update this keeps updating so these values will go in increments with these values constantly updating and going up we want to set our cameras field of view to those values so if i get the first person camera and i just left click drag this in and create a pin off and type in set field of view we now have a field of view here so on update we would set the field of view but we want to do something first because we won't know which value we want to choose so to select that i'm just going to use a stage variable and this is going to tell us which stage we are currently in be it one two or three so to do that i'm just going to go to our variables here in the left corner and as you can see i've created a stage variable and i've made it an integer so you just add a variable here type in the name so if i add a variable type it stage or whatever you want to call it and create it as an integer which is a whole number and i'm going to start off at stage 1 instead of zero just because i find that easier and it makes it less confusing so if we drag this in now and we get if we get our stage and we create a branch by holding b and left clicking or right clicking and typing branch we can get a condition here so our condition is we want to check the value of stage so i'm going to left click drag off stage and type in equals so equals integer so if stage equals a number and if that is true do this if it's false do that so for our first one i'm going to check if stage is one and if stage is one then we want to do the first field of view change and if stage is not one we want to do the next field of view change so i'm just going to copy this so like that but you might notice we have loads of different field of view changes so to get more i'm just going to do the same i'm going to create a new branch just copy the original and if it's not equal to 1 we now want to check if it's equal to 2 and then same again if it's true do the second field of view if not we want to do the third so i'm going to copy and create a new branch again is it equal to 3 if it is we want to do the third change if not we want to do the fourth change and i'm just going to hook up the first person camera on each of these so now we have this here how do we control this value stage value going up how do we know which stage we are in so to do that i'm going to do on the finish track so when this zoom function has finished so when one of these graphs has finished we want to get our current stage number so if we're in stage one we want that plus one to that to make it two if we're in stage two once this that stage is finished we're going to plus one so we're in stage three now so to do that i'm just going to create another branch unfinished and we're going to check if stage equals 4 because that is our final value so it keeps going up 1 2 3 4 and then if 4 has completed then we want to go back to zero so i'm just gonna move this out of the way so if we get stage set so if we're equal to four and four has just finished then we're gonna set stage back to one not zero because i set our first value to one if we're not at four yet then we want to add another value on so we're going to take stage the stage value and we're going to plus 1 as you can see here and we're going to do another set and we're gonna set it to that so the current number plus one makes us go on to the next stage so now we have that and this should work through we also want to check if we're zooming in or not so if we play this now and i right click you can see it goes like this and it is broke and that is because we haven't set the field of view values so remember zoom one is going to go at the field of view for our first stage zoom 2 is going to go in the field of view of our second stage 3 and then our final ones going to go zoom back out to the default compile and save that now we can see how this plays out if i right click with zoom one right click zoom again right click zoom again right click we zoom back out so what we can do as well to stop any jumpiness we can make sure we play from the start but we can also use a branch again and check if we're currently zooming so once the timeline starts to play a track then we're gonna be in zooming mode so to tell that i could create a new variable and i'm going to call it is zooming question mark and that is going to be a boolean so true or false and by default it's not going to be false because when we start the game we're not going to be zooming in but when the timeline is playing we're going to set zooming to true because we're now zooming and when we are finished so when we finished that stage of zooming we want to set it to false because we're no longer zooming and i'm just going to do this after our set stage just to make sure that we can't change the zoom before these values have changed just so we don't confuse the program so now start off with if is zooming if we're already zooming then we don't want to do anything if we are not zooming anymore then we want to play each graph from the start again and if we didn't have this checked we could be slowly zooming in but if we zoom from the start we can be halfway through a zoom and we press it again and it suddenly jumps the track and then we get a really jarring jerkiness so this just helps make things run a bit smoother so if we save this and play it now you can see our zooming moves in and as you'd see i can click the mouse as fast as possible but none of the zoomings get interrupted and we don't have that jerkiness so yeah that's how you set up the incremental zooming if you want to zoom even further of course you can open the timeline and you can set each value to a lower value so let's say we want to zoom in a lot at the end i'm going to change 45 to something like 15 and i'm just going to update the graph before the graph after rather the value to 15 just to match that now if we go back and play we zoom in a bit we zoom in a bit and then we'll zoom in a lot and we right click and we zoom back out so yeah you've got the flexibility of changing this graph and if you want the zoom to be slower just change the length of the graph or use last keyframe and set all of the last keyframes to a longer time frame so yeah i hope you found this helpful and i hope you can incorporate this into whatever cool project you're working on and as shown in the graph there is a crouch function which was my previous video so if that interests you at all check out the link at the end of this video to see that video but yeah uh i hope this tutorial was helpful for you if you're creating say a sniper scope or you're doing anything of that nature that involves zooming in i hope this was helpful for you if you found it helpful please do give it a like and comment down below if you found helpful if you have any problems please do let me know in the comments below the same with any suggestions um please consider subscribing it helps me out a lot and it is free so yeah please don't forget a like subscribe ring the notification bell and i'll see you in the next video thank you you
Info
Channel: 3D Ross
Views: 1,339
Rating: undefined out of 5
Keywords:
Id: HgEn7feTyJc
Channel Id: undefined
Length: 16min 59sec (1019 seconds)
Published: Wed Apr 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.