Spider Man Web Swinging Tutorial Unreal Engine 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this video i'm going to go over how to make a spider-man web swimming system when we are falling we can left-click and launch a web and attach ourselves to the near swing point when we let go we get a small boost and then we can attach ourselves to the next square point so the first thing we're gonna do is head over to our third person character and in the event graph in some free space we're gonna right click and look for event begin play and all of this event begin play we're gonna look for a set timer by event and under time we just want to make this 0.2 seconds and check the loop looping box every 0.2 seconds is gonna look for this event and off of the event we're going to drag and look for add custom event i'm going to call this look for swing point so every now 20 seconds we'll be looking for a swing point that our player can hang off so off this will look for sphere trace for objects so sphere trace for objects and then the start of the trace we're going to get our actor's location so we look for character location and just hook this up to the start then the end of the trace we're going to get this actor's rotation so if we'll forget active rotation then off the return value we're going to look for get forward vector and then we're gonna multiply this so look for multiply vector by float and we'll make this like a hundred and then we want to just add this to the original at location so this will do a sphere around our player and when it hits something we'll know so we're just gonna plug this into end and i'm gonna set the radius of the sphere to be about one thousand so of one thousand radius square around us and what we're looking for is an object type so we want to look for make array but we're going to be creating our own custom object type so we just compile and we'll head back to this later so we want to head over to settings project settings i'm going to be making our own object type that will be looking for so we'll look for collision and look for object channels and create a new object channel and we'll just call this swing point so we're going to be looking for these swing points and if we hear that we'll be able to swing from it so i'm just going to close this and we're going to set up an actor which we're going to be able to swing from so look for blueprint class actor and i'll just call this my swing point and if we double click can i go up you want to go to add component i'm going to look for sphere collision just select it and we scroll down under collision presets i want to change this to custom and object type we want to look for the swing point that we just made so we can see the swing points in our game i'm going to look for a static mesh and just scroll up and under stack matter and set the cube so that we can see where i can swing from in the game so i'll just click compile so now we get back to our third person character i'll do the make array okay it's not there so i'm just gonna close it because it probably needs to update and now if i just reopen the third person character we can look for swing point so every now point segments when we're looking for our swing point and if we hit it so off of this one not for branch and then off of the r hit we just want to look for a break hit value and then we want to check if we've hit the swing point actor that we just created so we'll look for cast to swing i think that's called swing point so classic swing point i'll cut this out and we'll just plug this into true and once we have this as a certain point we want to get the actors location so look for the access location then we right click on this promoter variable and this will be the swing point location so we'll need to know this so we know where to swing from so i'll just plug that in and once we've got that i'm gonna create a new variable and call it can swing as if we hit this then we know our player will be able to swing on it so we'll just say it and just plug that and take it so it's true and if we don't hit anything then we're gonna set set can swing to false so we'll just leave it unchecked so that we can check this is working in the game of this i'm not for print string and just plug this into the print string and click compile and we'll be able to just quickly see if this is working so i'm just gonna drag my swing point in and if i click play we can see it print strings every notebook you seconds the location of it so it had the correct values so you just want to check that that's working so now we have a system which finds our swing point so i'm just going to select all of this set c to comment it and call this my calculate swing location so i'm gonna how can i make it so that we can swing from stuff so if we look for the left mouse button when we press the left mouse button i'm gonna check for two things so we're first gonna create a branch and i wanna check that my character is falling through there so dragon character movement and look for is falling so my character has to be falling and he also has to have a swing point that you can swing onto so create another branch and check that we can swing and just plug this in so we're gonna be swinging with our cable rope so we're gonna just set that up in our character so if we hit compile and add to the viewport i'm gonna go to add component and look for cable and this will put a cable in our game and we're just gonna quickly modify a few seconds so we'll make the cable up one and it's iteration 16 and it will make its material the ramp material because that looks kind of whitish and then we're just one last thing we're going to set the cable width to be around two so it looks quite thin like a string so with the cable selected we'll go to the details panel and click hidden in game so by default we can't see this i'll just compile and then we want to head over to our mannequin who's his character folder to his mesh and to his u4 mac and skeleton and we're going to create a new socket for where this cable was going to be from so i'm going to make it on his right hand so i'm going to look for add socket and i'll just right click and rename this and i'll call this my swing so the rope is gonna go from that swing so it will start from his like hand on that swing socket so if we can twink the first thing i'm gonna do is drag in my cable and i want to set hidden in game and just check it check it so that we can see it in the game and then i'm going to set sorry set the location of the cable so we'll just plug this into that and we'll set the location of the cable to be the swing location of the actor that we're going to swing to and then we're going to set the end location of this cable so we'll look for set end location plug is in and the end location is we're going to get our mesh we're going to get sorry get socket transform and under socket name we're going to change it to swing and then right click split this get the return value and that'll be the location so that'll be the swing location that we set up in our mannequin and then after this i'm going to get the artist location and then we're going to get in minus vector then we're going to get in the swing location so i'm going to do this to calculate the length that our rope should be then off of this we're going to look for vector length and then i am going to minus float you know minus if i like a value of 400 let me right click on this and promote it to a variable and call this new cable length so this will be the length of our cable not so like how long it'll be from like the swing attachment to our hand and i'm just gonna double click and then off of this drag set cable length so there and then we can just hook this all up together so they'll work turn my hook cable length into new length and just plug this all in so once we've got that i'm going to create a new variable and call it attached so that we will move so that we know when we're attached to a point so we'll just set attached plug this in check that box and we can comment this code and call it attached so now we're going to set up so that we apply a four-star character when he's attached to a rope so i'm going to look for event tick so i'll apply this every tick of the second to every frame i'm going to create a new function and this will calculate the force that should be applied to our character when he's swinging so i'll just call this calculate whoops that's about that wrong very well and to calculate this force we want to make sure that we're at first attached to a point so we'll just drag in attached and just plug this into the condition then we want to head over back to the minecraft because we need to some of this is the same so we're just going to copy it so from the cable bit we're just going to copy all of this with control c and then go back to the calculation force and ctrl v to just paste it back and we'll just plug this into true and then we can delete this bit we can delete this as well and just plug that in and then we can just drag in our new cable lens so this is just to make sure that our cables maintains the length that is when we're swinging across it so i'll just move that back there so now we're going to do a formula which will just calculate how much force to apply to our character when he's swinging so we're going to drag in character movement and we want to add a force and to add this force we are going to we want to get velocity of the character then we want to get the actor's location and we also need to get the swing location so that that will be swinging from so i'm going to look for the dot product and plug that into there then from get access to location i want to drag off this and look for vector minus vector so minus from the swing location and sorry we need to plug that into the dot product then from this value we're going to do a vector multiply float and then we'll just plot normalize this value first and then plug this in here and then we want to multiply this vector by a float and we want to multiply it by -2 and this will calculate the force that should be applied to our character when he is moving through the air when he's attached on the rip so we'll just plug this in then there's one more thing we'll do we'll drag in his character movement and set air control so that he has good control when he's flowing through there and i'll just set her too and then i think we're done so we can compile and then we'll just drag in the calculate swing force and plug this into event tick and compile and we can test this out so before we actually play it i forgot to do a few things so we just need to change this to rts actor and uncheck this because that will actually make it so that the rope's hidden in the game and we need to do the same with our calculation for so just uncheck that so we can see the rope and this needs to be rts actor for this to be correct so now we click compile close this drag in our swing point and then click play now if i press the left mouse button we're now swinging from this point so now we're going to set up the rest of this so i'm going to head to the event graph and move this down and just press c to comment it and call this calculate swing force so we know what it does sorry i spot that horribly so now i'm going to set it up so that when we let go of a point when we're still attached it will boost us in the air so when we release the left mass one i'll make it launch our character up in the air a bit if he's still swinging so we'll look for a branch we want to check the archive is still attached and then heavy still attached we're going to get the velocity of the character so we'll right click look for get velocity then we're going to add vector 350 so i'm going to launch about 350 and then to make this launch on the character for launch character plug this into the launch velocity plug this into this true so launch our character when we let go of the swing point and then once we let go i'm gonna set it so that we're not attached anymore so look for set attached and uncheck it and then we want to drag in our cable and just set the end location to be zero so we're not attached to a swing point anymore and then off the cable again we're going to set hidden again so we can't see it and we want to make sure it's checked so we can't see the cable anymore and then we will just drag sorry i'm gonna look for character even and we're gonna set his air control and i'm gonna set it back to the default value of 0.2 and just plug this in and click compile so now we can let go of our rope so when i click play and i press and hold the left key then i let go i'm free and then if i press and hold it again i'm now swinging and we can just use this to swing about and swing around oh objects so now we are going to set up the animations of it so that it looks like he does swinging animations and everything so if we go to the mac and animations folder i will leave a link in the description of some attached animations so we have two animations we have a swinging animation and a swing animation we'll just drag them in i'm just getting turned around it's like key for mannequin clicking portal for the start swinging animation reader double click open that up scroll down and click enable root motion and save this then we want to right click on the start so again create and create another montage and then we don't need to mess with the other one so go to the third person animation blueprint and we want to head over to his animation graph of the default we'll look for default slot and just plug this in this will allow so that we can reference and play animation montages later in and we're going to set up a swinging state so i'm going to drag in his um swinging animation and from the jump start i'm gonna plug it to swinging animation and i'm gonna create a new variable called swing king and just double click and open up and when we are swinging we will play our swinging animation and to exit this we're gonna drag off it and plug it into jump loop and just double click on this dragging swinging and look for not boolean and just plug this in and compile so now when it's up in our third party character so it references these animation states and does all the animation montages we just set up so if we head before the branch i'm just going to move all of this back this is going to be where we're going to place our animation montage off of branch we will look for play animation montage and i'm going to select the start swinging montage so i'll play this when we've got a point to a swing game attached to and then after it plays the animation montage after all of this we're going to drag in our mesh clip for get annum instance this will allow us to reference the animation blueprint so all for the return value will look for class 2 third person animation blueprint and from here we can set the swinging state to be true so set swinging check that box plug this in then plug all that in then we just want to move this and we're going to copy it with ctrl z and ctrl v and we're just going to uncheck some game when we let go of the rep so when we un hold the left mouse button and click compile so now our character will have some animations when he swings so he's just swinging and swinging okay so that looks a bit weird so um so there are two ways we can fix that the first way we can make the distance between the two swing points further away so that we don't end up on top of the swing point to fix that i'm just going to go back to the third person character i'm going to say air control to be 0.6 because the default value of 0.2 is too low for me and if we head over to the swing location we're going to get our axis location and then we want to right click split right click split and if the z so if we're above the swing location then we're going to make it so we can't swing or attach to that point so i'm going to create a branch and just plug this in and if it's false then we can uh we can swing but if we're above it then set so that we can't swing on it so we can't get that so we can't attach if we're above from that point so whenever i click play run swing i do my swinging animations and then i'm above so i can't swing and then when we blow it we can start to swing and attach from it and that is how to set up some swinging spider-man swinging in animation if you enjoyed like subscribe it helps the channel out and i will see you next time bye
Info
Channel: Unreal University
Views: 38,402
Rating: undefined out of 5
Keywords: unreal, engine, tutorial, ue4, learning, unreal engine, game engines, gamedev, dev, programming, blueprints, coding, game builder, education, learn, code, game, development, web, swinging, spider, man, spiderman
Id: 8oc4ZCNJ9wM
Channel Id: undefined
Length: 19min 37sec (1177 seconds)
Published: Sun Dec 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.