Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now that we have prepared this wall, we can finally work on the wall slide and wall jump.
The way a wall jump works is actually quite different from game to game.
And the method we're going up for is that it's broken down into two parts.
We have the part where you just jump on the wall and we start sliding down, and we have the other part
that if we press a button while we are sliding, we jump to the other side.
Some games don't have the sliding part, and they simply make you jump if you press while you close
and jump again.
But we're going to break it down into the sliding and take care of that first, and then go into the
jumping part.
And the way this works is that while we have to detect if the wall is nearby and if we are falling,
and to do that, we're going to shoot out a line trace to trace for the wall and check if the wall is
close enough and if that is the case and we are falling down, we clamp the downward velocity of the
player to make sure we just slide down very slowly.
Most tutorials I've seen on this topic actually use a different method that doesn't clamp velocity,
but lowers the gravity and I also looked into that method by actually found it buggy.
And it doesn't work as well as the clamping velocity method because this covers more edge cases.
Now let's open up the BP player.
We can close everything else and we want to find the tick event.
So on the event graph if we can't find it here, just control F and just look for tick.
And we don't have the tick yet.
We actually haven't implemented the tick yet for the player.
So that's what we can do.
Now I like to have the tick close to the beginplay, so we can just open up some space here and just
right click and write tick event tick.
And again we want to make sure to call everything on the parent first right.
So right click here and call Add call to parent function.
And just plug this in here also the delta time.
And now we just execute everything on the parent first.
And then we put in our own implementation for the BP player.
The first thing we want to do on tick on every frame is a line trace.
Because on every frame we want to check if we are close to the wall so we can latch on to it or not.
And the line trace is pretty much like a sensor in the game world.
And you can just like draw a line forward and check if you're hitting something.
So here just right click and type in Line Trace.
And you can see there's multiple types of line traces.
In this case we do not need a multi-line trace.
Multi-line traces for example would be in a shooter game if you want to shoot through a wall.
So maybe if you shoot through a wooden wall it would still hit the person behind it, but maybe deals
less damage.
And for something like that, a multi-line trace is perfect.
However, we just need something simple.
So we just need a line trace.
We can have by channel, by profile or for objects.
And the one I want to use in this case is line trace for objects.
And everything kind of works the same.
Right.
All of these different types have the start, the end.
But the difference here for objects is that we get this object array where we can set the object types.
And using object types is the easiest way to detect a wall or something in the stage.
Then just connect this here on tick.
And first let's look at the object types right.
So here we can just make an array.
Of object types.
And here we can pick all of the different object types we want to check for.
But for the wall slit, of course we don't want to check for projectiles.
We don't want to check for pawns.
We only care about walls for the wall slide.
So the only thing we need is world static.
Next we need to set.
Where do we want to start the line trace and where should it end?
For now, we just want to start directly from the middle of the player.
Right.
So we can just get actor location.
Get actor location.
And this is just the start position of our line trace.
And we want to trace forward.
So the end location should be our current location of the player and forward a little bit.
And the way we can do this is by get actor forward vector like this.
And this just gives us a direction.
So it's going to be a vector of 100.
For example, if we're looking to the right.
And we can then multiply this by the amount of distance that we want to check.
And here we get a vector.
But we actually want to right click this and to float single precision.
And here for example we could just put in like a 200 units to check 200 units forward.
So all this does is it gives the forward direction and it multiplies it to check 200 units forward.
And we need to add this to our current location.
Otherwise if we just connect this this would just be from the zero position in the stage.
But we want to relate this to the actor location right.
So here we can just plus.
And plug this in here.
And this is our end location now.
So this might look a bit confusing, but if you work with line traces more and more, this is actually
quite simple and it's going to start making more sense.
But let's just have a look at it.
And to be able to see what actually happens here on the draw debug type, we want to set this for one
frame.
And now let's just try this out.
It should already work.
Compile and save.
And I go here.
And you can see this red line in front of the player.
It might be a little bit small but you can see it right.
And if we hit something you can also see this red block where we hit the wall and on this side as well.
Right.
You can see this red block and you can also see this green line.
Right.
So the green line on the other side is just the length.
But we already hit something.
So we don't really check anything after.
But it just shows us the length still.
Right.
And you can see we are already correctly detecting the wall which is exactly what we want to do.
And it also works that we do not detect the enemy, right?
It doesn't show this block.
It ignores the enemy and it only checks for this world static.
But of course the trace is way too long.
We don't want to start sliding if we are this far away from the wall.
This was just for showing you how this works.
So now we actually want to make sure it is of a reasonable length and it is not 200.
And what we want is that it starts in the middle.
Right.
And it should be a little bit wider than our capsule.
So we can actually look at the capsule and we can see that the capsule radius is 34.
And since the radius is the half of it, it means from the middle point to the side of the capsule,
it is 34 units.
And our trace should be a little bit bigger than this.
So I think about 40 units is a good value.
And we can go back here.
And now just type in 4D like this and compile and save.
And you can see it is much shorter now.
But still, if we close the wall, you can see the red block shows up.
And I think this is about the right amount where we should start to slide down the wall.
And now of course, we just want to turn this into a variable.
So promote the variable and call it wall trace length.
Like this.
And this is the first step we need.
And here we then get the output of is true or false.
Right.
So we can print true or false.
And this shows us if the wall is next to us or not.
Right.
So false false false true true true true true.
And we can then use this to set us to wall sliding or not wall sliding.
Right.
So let's do this.
Now instead of the print string we can just have a branch here.
Like this.
And we want to create a new variable and it's called is wall sliding.
And it should be a boolean.
This is fine.
Compile and save.
Default value is false.
This is fine.
And now here we want to set it.
So if this is true, we know that we have a wall next to us.
We are checking the wall.
So we want to set this to true.
We are wall sliding.
And we can just copy paste this here.
And if this is not the case well we want to set this to false.
Right.
Because we should not be wall sliding if the trace doesn't hit anything near us.
And this boolean by itself doesn't do anything.
But this is what we're going to use in the animation graph to show the wall slide animation, and also
check if we are able to wall jump.
The velocity clamping is the most important part, but this is actually very simple to implement.
So in the case that we have the wall next to us we are wall sliding.
We just want to get the character movement component.
And here we set velocity.
All the way at the bottom.
So this lets us manually override the velocity.
It lets us overwrite the physics to pretty much just set our own velocity that we want it to have.
And what do we want to do here?
Well, we do not want to change the x and y velocity.
So left, right, back, forward.
We don't want to change anything.
We just want to put a limit on the downward velocity.
So here we can right click and split struct pin.
But we need to know our current x and y velocity because if we just leave this as zero, it is actually
going to set it to zero, which is something we don't want.
So again, we can copy paste the character movement and get velocity.
Get velocity.
And here we split the struct pin and we just plug in the velocity x and the velocity y.
So we just plug in the current velocity for the new velocity.
And this is just the way you usually do this.
But we also want to take the z velocity.
We don't want to completely overwrite it.
We just want to put a limit on it.
And how can we put a limit.
Well we can use clamp for example.
Sorry, not this one a clamp float for example.
We can use this and put a max and a min value.
But in this case we actually only care about the minus value.
So instead I think it's better to just use the max node.
Max.
Sorry Max.
Float and connect this here.
Go like this.
And here it's then going to pick the biggest value.
So it's going to pick Z.
If z is bigger than 0 or 0, if z is a smaller than zero, but zero is too small because zero means
we're never going downward.
Right.
So if I show you this, we just get stuck on the wall, right?
So we just do this and we kind of almost get stuck because we cannot override physics 100%, but we
just kind of slowly go down.
Um, but we want to give it a little bit more speed.
So here we can actually go -20.
And this is going to be the fastest value we can go downward like this.
And this is a little bit better.
But if you want to slide even faster, you could adjust this value to, let's say, -100.
For example, and you slide faster.
But I think -20 is a good value for now.
And we can then of course set this to a variable.
So just drag off here and promote the variable and call the wall slide speed.
Like this.
We might adjust the actual value after we have the animation, everything else in, and we can get a
better idea of how it feels like.
Now we want to make some adjustments, because one thing I don't like is that even if we jump upwards,
it also kind of like puts us into the wall sliding state already.
We only want to be able to go into wall slide while we are falling, right?
So not while we go upward, just while we are falling.
And there's an easy check for this.
So on the tick, before we do any of this, before we do all of this, we just open up some space.
And we add a branch.
So here we just add a branch.
And we just check for our velocity.
So on the character movement get velocity all the way at the bottom.
We only want to check the z velocity.
So here we can split the struct pin and we simply check for smaller equals and not zero.
Well we want to be falling at a certain speed first.
We don't just want to snap right to the wall.
So I think about -50.
So if we're going -50 downward it's going to start to actually line trace.
And then only then allow us to go into the wall slide state.
So let's check this out.
I go here and I jump upward.
It's fine.
Only like after we go down.
And this might be a little bit hard to tell because this is going to make much more sense once we have
the animation in.
But this is just a lot smoother for gameplay reasons than just clinging onto the wall even while you're
still going upwards.
That just doesn't make any sense for our game.
And yet another addition is that I don't want the wall slide to be active unless I keep holding towards
the wall.
Now I just let go of the button, but we still are in this wall slide state.
I only want the wall slide while I keep holding towards the left wall, and we need to add another condition
for this as well.
So back here where we do the check for the is falling and the easy way we can check for this.
There are multiple ways you could do this to check for like the wall direction, all of these fancy
things.
But I think the easiest way to do this is to simply check if our input direction is the same direction
that our character is facing, so we can get actor forward vector.
Again, we only care about the x, we can split the struct pin, we only care about the x, and we also
want to get I a move.
So the enhanced action value right.
So we have the eye move event right here on the event graph down.
Yeah we have the eye move.
And this is the event for our left and right input on the keyboard of course.
But we can actually also get the current value anywhere else in the blueprint which is again a very
nice feature of the enhanced input system.
So just to show you how this works, let me just put this back here so we can always wall slide and
just print string here.
Right.
Print string.
The IA move.
Now, if I start the game, you can see it's zero.
Because I'm not pressing buttons, I press left.
It's minus one, I press right, it is plus one.
So again minus one is left, plus one is right.
And the same goes for this actor forward vector on the x right.
So I can print this I see right is one and left is minus one.
So we just have to compare these and see if they are the same.
But one problem with float comparisons is there are floating point rounding problems with all computers.
This is again a computer science topic.
I'm not going to go too much into detail in, but the thing is, you actually cannot compare a float,
right?
I could do equal, but in many cases it's not going to work because even if it says minus one in the
computer, it might be -0.9999999997.
And you never want to compare floats.
We could use a nearly equal and put in an error tolerance.
This would work, but there's actually an even better and easier way.
We simply have to multiply these.
So just multiply.
And if both of these are plus, well, we're going to get a positive value that is bigger than zero.
If both of these are minus we're going to get a negative value.
And this is just a nice math shortcut we can use without having to use the nearly equal and put in a
tolerance and deal with all of this.
So here we just check for bigger or greater than zero.
So if this is bigger than zero, it means we are pressing the button in the same direction that we are
looking.
If it isn't, it means that the direction we are looking and the button we are pressing is different,
or we aren't pressing any button at all.
And we can just connect this here and then use this and right.
So these are our two conditions.
And of course we also connect this here.
Don't forget about this one and compile and save.
And here I hold the button and I let go.
And you see the line.
Trace stops.
We fall down normally again I hold the button, we slide.
And this is exactly what we want.
And I cannot show you this on the right side now because we don't have it.
I actually can see a little bit, but it is hard for us to test on the right side yet because we don't
have a right wall.
Well, here you can see it.
It also works for the right side.
If I let go, we fall so it doesn't just work on the left side.
It also works on the right side.
And this is how we implement something like this.
Now denotes look a little bit complicated.
And if we look at this later we're going to be like what what was I doing here.
So we can actually collapse these nodes and just give them a name to make it a little bit easier for
us.
So here we can select these three and just collapse nodes and just say is descending.
So we know what we want to do here.
And then in here we have all of this, of course.
And here we just want to check for is holding towards wall.
So collapse nodes and just say is holding towards wall.
And all of this does still the same thing.
It's just better to look it easier to understand what is going on here and next.
We can also collapse all of this, right.
All of this wall sliding logic.
For now we are completely done with this.
The wall sliding itself.
So we can just select all of this, make sure to not select anything on the upper row.
And we want to collapse this to a function.
So right click collapse to function and just call try wall slide.
And then drag it over here.
And again, we cleaned up a lot of the space in our event graph.
Everything is nice encapsulated in here.
And these came with us.
These nodes came with us.
And I think these are just like small things.
There's no point in putting these into a function unless we think we're going to reuse them.
So this is why I chose to just collapse the nodes instead of making functions.
But both are valid options.
And here we just have the rest of it, right?
Everything is working.
We still want to keep the debug type showing.
And this was pretty much all we have to do for the wall sliding.
And this might have sounded like a bit of an intimidating topic, but I think you've seen that it is
actually not that hard after all.
It took me a while to figure out this really streamlined and good method, and I hope you learned something
from this.
And in the next lesson, we're going to implement the actual animations to make it look nicer.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.