Unreal Engine RTS / City Builder Camera Control Set Up - Beginner Friendly!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to this video in this video i'm going to be showing you how to set up movement uh camera movement and camera zoom in like a top down kind of rts city builder kind of game mode but we're doing this in unreal engine 4.25 and we'll be starting with a blank project so let's just jump straight into it um so you want to do is once you've got your engine installed create a new project i'm going to make a blank project it's going to be blueprint you can do this in c plus if you want to the logic is the same but obviously you'll be doing it in code as opposed to blueprints and once it's working in blueprint if you want to you can put it into c plus um so i'm just going to make a new project i'm just going to call this rts camera project we'll just create that project um you could choose where you want to save it and then i'm going to hit create project and just wait for that to load okay so that's now loaded and you can see we've got a completely blank project okay there's nothing in it it's just our kind of default world nothing in the content browser but we're going to change that now so if you right click in the content browser and go up to blueprints and then make a new blueprint you can select uh first we need to make a new game mode um so we can swap the default pawn so i'll be clicking game mode base and then we'll just call this bp underscore my game mode just like that gamdi mode game mode and then straightaway i'll make a new blueprint i'm going to set this as a pawn which means that we'll be able to possess it and use it as our camera movement i'm just going to call this my pawn now if we go up to project settings up at the top this may not be here you may just have this you can go to edit project settings um i always keep it docked here because i found i'm going in and out and adding inputs and stuff like that and we're going to do a couple of things in here the first thing we want to do is go into maps and modes and then where it says game mode base we want to select bp my game mode which is the one we just made and then if we spin out this uh selected game mode under default pawn we can select uh bp mypawn you there's no save button that just saves automatically if you go back to untitled um and if we hit play see now where our default pump we can't move um it just spawns in we have a camera like looking at the world but we can't do anything so to help manipulate this pawn we need to go back to our project settings and set up some inputs you're going to want a couple of inputs here make two axis mappings just to start with i'm going to call this one move forward and then we want a move right and now to move forward we're going to use w on the keyboard and that's going to be scale 1 which will be moving us forward and then we can do s as our second input and we'll swap this over to -1 for move right and we're gonna want d on our keyboard and that's one a scale of one and then we want a scale a to move left and that's gonna be a scale of minus one um and actually we wanna be able to rotate the camera so we want a uh rotate cam and for this i'm gonna select e as my rotate button and that's gonna have a scale of one and then i'm gonna press q and have this a scale of minus one and then the last axis map in i1 is a camera zoom we want this to be the mouse wheel axis and we want this to be minus one um because currently if we left l1 when we scrolled the wheel up we'd zoom out and when we scrolled it down we'd zoom in which isn't kind of how i'd want to if you wanted it inverted you can just carry and follow along but leave that as one but i'm going to go with minus one with that all set up if we go back to our blueprint my pawn i'm just going to dock this over here so you see this our pawn there's nothing on it and currently we can't really do anything or manipulate anything um so we just want to fix that so first of all i'm going to add in a spring arm component and then i'm going to select the spring arm component and then add in a camera so you can see that our spring arm here when we move this it's controlling our camera and with the spring arm to zoom in and out we're going to be manipulating this so as the target arm length comes down we zoom in and as we increase the target arm length the camera zooms out and now for the top down look i'm going to press e on the keyboard to get the rotate wheel i'm just going to turn up you can go kind of full on 90 degrees which is going to be completely down or we can go kind of 70 degrees and that'll give us a bit more of a kind of angled top-down look it's up to you what style you want this is going to work either way and this is just personal preference and then we also want to add in a floating pawn movement and then just hit compile hit save and then go over to the event graph so in the event graph if we just go to a blank area and if we search for the input axes that we set up before and make sure you get the access event not the access values so that was moved forward then it was move right and we had a rotate right nope that's not what we want but i'm sorry we had rotate cam and then we had a zoom camera zoom so straight off the bat i'm just going to make a couple of functions here to keep our code nice and tidy um so the first function i'm going to call i'm going to call it move forward and then we're going to have a move right then a rotate cam and then finally a camera zoom function and let's just drag these out onto here and connect them up and hit compile and then on all of these i want just to add an input parameter and i want this to be a flow i'm just going to call this axis value and i'm going to do this on all of them and now we can take our axis value here and just pass it in just so this is all set up ready for us to use it so going into our move forward and it's very simple we just want to get an ad movement input and drag this up here connect this to here connect the axis value to the scale value and then we want to get get actor forward vector and then plug that into there hit compile go over to our move right add movement input again just connect these up and then we want to get uh get actor right vector we press compile hit save then press play see that now with wa s and d we're moving our camera around if you want a bit of control over the movement speed as you saw that was quite fast what you can do is if we make a variable here called movement speed make this a float hit compile so now we can set a movement speed i do 0.5 drag this out if you hold down control and drag out that gets it so you can get the value there and then we want to come off this press asterix to get a multiplication i'm gonna drop drag this into the top slot this one into the bottom one and then plug that in there i'm just gonna select these two nodes press ctrl c and then just drop them over here and do the exact same thing drop that in there drop that there hit play now you can see it's a lot slower [Music] so you might want to change this to say 0.7 i'm liking the way that's feeling you can also have a bit of control over it under the floating pawn movement you can set the max speed the acceleration deceleration you can change all that and play with that to get kind of the movement that you desire so those functions are done we can close them now for the rotate camera function uh this gets a little bit more tricky we just want to right-click and then get set actor rotation drag that over here and now we want to get the current actor rotation drag this off and do a break rotator just so we can keep it a bit more organized i'm going to come out the axis value press asterix to get a float i'm going to right click and promote this to a variable and i'm just going to call this the camera rotate speed i'm just going to set this to a value of 2 for now from this set actor rotation i'm going to come out with here choose make make rotator now we want to plug the roll into the roll to pitch into the pitch and now your is what's going to rotate our uh pawn so if we drag a uh say a cube into the world you can see that this red arrow is our forward vector and if we wanted to rotate the camera would use the blue rotation here which if you go up to the details panel you can see that the blue rotation is the your so that's the one that we need to manipulate to spin our camera around so i'm going to go back to our rotate cam i'm going to take our current yawn add the new value to the current value and then set it here so we press compile and click play now as you can see we're going around and if we press q this rotates our camera around and then if we press w we go forward compared to our new rotation if you hadn't have done this based on the forward vector and you were just manipulating the actors like position in the world and things get really confused and as you spin it ends up messing up the controls so this is why we've had to set up using the forward vector so we always know that we're going forward relative to the camera so you can see we can spin we can move forward and we can manipulate through our world you see a bit of an issue there where as we go over to the cube um it's clipping we can fix that if we go up to my pawn go on to the spring arm and search for collision and let's do collision test we uncheck that and then press play you see that that doesn't happen now uh what was happening is the camera was inside the cube and it was freaking out a bit another way to avoid that is if we drag the player start just up slightly just so it's off the ground plane um our actor will spawn here um not down here so we press play we're a bit more zoomed out but we wouldn't have been hitting the camera anyway okay so that's moving forward and rotating the camera setting uh so so we just need to do the camera zoom now so we just want to make a variable down here it's going to be a float again we're going to call this cam zoom destination and then i'm going to hold down alt to drag this and i'm just going to set it here and what we're going to do is we're going to eventually go from the current target arm length to our new destiny destination and we're going to interpolate between those two values smoothly and to get a nice kind of smooth scroll zoom in so to do that we want to get a reference to our spring arm by holding our control and dragging our spring arm in and if we come off the spring arm we can set target arm length i'm just going to drag this here out of the way so now i'm going to make another variable called zoom speed again this is going to be a float and i'm just going to set this by default to around about 50 and again we can tweak this depending on how we think it feels for our game the first thing i'm going to do is i'm going to hold down control get the zoom speed come out of the axis value multiply float by flow drag in the zoom speed up here and drag this back and then from here i'm going to add that add this destiny add this uh zoom to the camzoom destination and i'm going to set the cam zoom destination to our new value so what this is doing is it's again the current destination and it's adding the new value to it which changes where we're going to want it to go so now we've set our camera zoom destination if we come out here to an f into two then we can plug this into the target arm length and we want to interpolate i'm actually going to hold down alt and click um current to clear that so what we're going to do is we need to interpolate between our current arm length and then the new arm length which is this cam zoom destination so to do that i'm going to bring our spring arm back and get the target arm length so we're going to go from our current target arm length our target is our new target arm length i'm going to call i'm going to rename this just to make that make more sense so this is going to be the new target on length and we're going to get the world built to seconds to plug into the delta time and then our inter speed is going to be 15 and again let me change this depending on what we feel is right so we hit play you can see that that now works we can zoom in it's quite a nice smooth zoom hey but currently we can carry on zoom in forever and ever and ever which we don't want them we want to set a max distance and a minimum zoom distance so i'm just going to drag this over and i'm going to right click and i'm going to get a clamp lope and drag this up here i'm going to get this value and i'm going to make it so i'm going to right click on minimum provide this to a variable i'm going to call this the minimum zoom level i'm going to right click on max here that's a variable and i'll call that maximum zoom level and i'm going to change our minimum here for a default to be 100 and then maximum to 600. i'm going to compile and save hit play you can see that as we zoom i can't i'm carrying on scrolling but i can't go past the 600 target arm length and when we zoom in i can't zoom more than a hundred if we wanted to we could change this to 50 press compile hit play and that would let us zoom further in and then kind of the final thing i'm going to do is on begin play i'm going to grab the spring arm set the target arm length and i'm going to set this by default to half of the maximum zoom i'm going to get the maximum zoom level float divide by float divide this by two so that'll take our maximum zoom level harvey and it'll set our target only to half of this and then we're also going to need to get our new target arm length and set that to this value just so we don't end up zooming in and straight away from the start and just to make sure all of this is working i'm going to print string and i'm going to print the value of our target arm length just to test that that's working as you can see here we're at 300 which is half of our maximum zoom if i scroll in i've gone to 50. never zoom out i've gone up to six well close to 600. so we can move around we can zoom in we can rotate we can carry on moving we can rotate a bit further if you don't want them to be able to spin all the way around you can feel free to put a clamp in on that value to make sure they can't go uh more than sort of like minus nine to positive 90 which you can see i've just added in here so that would be take the your from our rotation and just clamp it between minus 90 and positive money you might even want to do minus 45 245 so now as we rotate we can only go so far in a certain direction so yeah hopefully that all made sense if you've got any further questions make sure you just leave them in the comments below and i'll definitely uh get back to you i'm gonna put this project onto my patreon so if you if you head over there and you can subscribe you'll get access to all of my previous tutorials blender tutorials and any uh unreal engine tutorials i do if you watch this video and it helped you on your game dev journey it'd be great if you could give me a like and consider subscribing to see more of these videos i do in the future but for now thanks for watching and i'll see you guys in the next one bye
Info
Channel: Dan Pos
Views: 13,558
Rating: undefined out of 5
Keywords: game dev, game design, unreal engine tutorials, ue4 tutorials, unreal engine 4 games, game development, game development tutorial, game design basics, unreal engine rts tutorial, unreal engine city builder tutorial
Id: gTbWVpmy1DI
Channel Id: undefined
Length: 17min 22sec (1042 seconds)
Published: Sat Jan 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.